2009-01-31

svn portable

Apache 集成 Subversion 的Win32便携式版本。
用做个人的版本管理之用。

集成环境为:
Apache 2.2.9
PHP 5.2.6
Subversion 1.5.5

默认解压到 D:/ 下运行里面的 install.bat 就能用了。
若解压到其它地方修改 D:\svn\svn-win32-1.5.5\conf\httpd.conf 中的 ServerRoot 到正确的位置。
默认项目数据保存在 D:\svn\svn-win32-1.5.5\svn_data 中。
(注:会注册服务 Apache2.2 ,若以前安装有 Apache2.2 就会安装失败。)
运行 start.bat 启动
(注:启动HTTP服务会用 80 端口,若被占用 则启动失败,在 D:\svn\svn-win32-1.5.5\conf\httpd.conf 中修改。)
运行 uninstall.bat 卸载。


访问 http://localhost/ 可以进行简单的管理:
创建、删除 项目
创建、删除 帐号、修改帐号密码

修改帐号访问权限现在还是需要自己修改文件
D:\svn\svn-win32-1.5.5\conf\svn\authz

文件下载:svn_portable.zip

// EOF Read More...

2009-01-21

在程序中处理设备的热插拔通知

注册 WM_DEVICECHANGE 事件,但还不够。
仅注册该事件则仅仅只会收到 DBT_DEVNODES_CHANGED 通知(包括光驱的弹出、收入,网络的通断等都会触发该事件)。
所以还需要用 RegisterDeviceNotification() 注册相应的设备通知。

HDEVNOTIFY RegisterDeviceNotification(
  IN HANDLE hRecipient,  // 注册 WM_DEVICECHANGE 事件的窗口或Service句柄
  IN LPVOID NotificationFilter, // DEV_BROADCAST_DEVICEINTERFACE 结构
  IN DWORD Flags
);

BOOL UnregisterDeviceNotification(
  IN HDEVNOTIFY Handle  // RegisterDeviceNotification() 返回的那个Handle
);
在 DEV_BROADCAST_DEVICEINTERFACE 结构里有个 dbcc_classguid 为需要监听的设备 GUID。
MSDN 上说 RegisterDeviceNotification() 的 Flags 加上 DEVICE_NOTIFY_ALL_INTERFACE_CLASSES 后可以不要GUID 但我这里似乎 不能不要GUID~~ RegisterDeviceNotification() 时失败说 “Bad Data!”~ 不知道是怎么回事,也许没用对吧。

参考:
http://www.microsoft.com/whdc/Driver/tips/PnPUmNotif.mspx
http://msdn.microsoft.com/en-us/library/aa363211(VS.85).aspx
http://msdn.microsoft.com/en-us/library/aa363431(VS.85).aspx


另外,在 Linux 上的热插拔通知 可用 udev, HAL, D-BUS。

//EOF Read More...

使用 RegEnumValue 要注意的地方

LONG RegEnumValue(
  HKEY hKey,              // handle to key to query
  DWORD dwIndex,          // index of value to query
  LPTSTR lpValueName,     // address of buffer for value string
  LPDWORD lpcbValueName,  // address for size of value buffer
  LPDWORD lpReserved,     // reserved
  LPDWORD lpType,         // address of buffer for type code
  LPBYTE lpData,          // address of buffer for value data
  LPDWORD lpcbData        // address for size of data buffer
);

返回值 ERROR_NO_MORE_ITEMS,表示都枚舉完了。
dwIndex 為索引,如果是枚舉并刪除的話,就一直為0就行了。
lpcbValueName 這個是ValueNameBuffer 的大小,這個地方要注意!!每次調用前設置成buffer大小,調用后都會設置成返回的ValueName實際的長度,所以這里需要在每次調用前都設置一下,@@ 暈死~,沒注意看MSDN。
lpcbData 同上。

//EOF Read More...

2009-01-12

google又换favicon了

今天发现google的favicon又换了,这次是几个鲜明的色块,不太喜欢这样的 -_-
//EOF Read More...

2009-01-11

修改文件/資料夾的用戶訪問權限

用WinAPI:

BOOL SetFileSecurity(
  LPCTSTR lpFileName,  // address of string for filename
  SECURITY_INFORMATION SecurityInformation,
                       // type of information to set
  PSECURITY_DESCRIPTOR pSecurityDescriptor 
                       // address of security descriptor
);
如:
::SetFileSecurity(szFileName, DACL_SECURITY_INFORMATION, psd);
其中 psd 的取得見上一篇:http://dave3068.blogspot.com/2009/01/securityattributeslpsecuritydescriptor.html

另外,對上一篇的補充:
SECURITY_ATTRIBUTES 中 lpSecurityDescriptor 的使用還可以使用 API :
SetSecurityDescriptorDacl
SetSecurityDescriptorControl
等。
不過感覺一般情況下還是這個 ConvertStringSecurityDescriptorToSecurityDescriptor 方便些 :)。
要如何使用就要看具體的場合了。

//EOF Read More...

2009-01-10

SECURITY_ATTRIBUTES.lpSecurityDescriptor 的使用

在 WinAPI:CreateFile 等函數中有個 SECURITY_ATTRIBUTES 可以用來控制文件的用戶訪問權限,但一直不知道SECURITY_ATTRIBUTES結構中的lpSecurityDescriptor如何設置,今天查了一下MSDN發現可以用函數:

BOOL WINAPI ConvertStringSecurityDescriptorToSecurityDescriptor(
  __in   LPCTSTR StringSecurityDescriptor,
  __in   DWORD StringSDRevision,
  __out  PSECURITY_DESCRIPTOR *SecurityDescriptor,
  __out  PULONG SecurityDescriptorSize
);
來設置pSa->lpSecurityDescriptor。
要使用該函數需要引入Sddl.h 頭文件,但 VC6 里面沒有這個頭文件。
還有個方法是自己 LoadLibrary => GetProcAddress 來取得:
ConvertStringSecurityDescriptorToSecurityDescriptor 在 Windows 2000 Professional 以上的 Advapi32.dll 中。
可以用以下代碼得到:
typedef BOOL (WINAPI *FN__CSSDTSD__) (
  IN LPCTSTR,
  IN DWORD,
  OUT PSECURITY_DESCRIPTOR *,
  OUT PULONG);

FN__CSSDTSD__ ConvertStringSecurityDescriptorToSecurityDescriptor = NULL;

//   SDDL   Version   information
#define SDDL_REVISION_1  1
#define SDDL_REVISION  SDDL_REVISION_1


void _initLIBS()
{
 HMODULE hAdvapi32 = ::LoadLibrary("Advapi32");
 if (hAdvapi32)
 {
  ConvertStringSecurityDescriptorToSecurityDescriptor =
   (FN__CSSDTSD__)::GetProcAddress(
    hAdvapi32,
    "ConvertStringSecurityDescriptorToSecurityDescriptorA");
 }
}

參考:
http://msdn.microsoft.com/en-us/library/ms717798.aspx
http://msdn.microsoft.com/en-us/library/aa379570%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/aa376401%28VS.85%29.aspx

//EOF Read More...