注册表不能添加键
用C++调用WINDOWS API:RegCreateKeyEx、RegSetValueEx在注册表中增加子键以及键值。函数执行结束后未看到新键值。代码如下:
HKEY hKey = NULL; char buffer[MAX_PATH]; DWORD dwDispos = REG_CREATED_NEW_KEY; char szNewKeyName[MAX_PATH] = "Software\\Microsoft\\WindowsNT\\CurrentVersion\\Winlogon\\Notify\\NTServer"; LONG lRet = RegCreateKeyEx( HKEY_LOCAL_MACHINE, szNewKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDispos); if(ERROR_SUCCESS != lRet) return; RegSetValueEx(hKey, "Asynchronous", 0, REG_DWORD, (BYTE*)1, 1); strcpy(buffer,"C:\\Hooks\\HookAPI.dll"); RegSetValueEx(hKey, "DllName", 0, REG_EXPAND_SZ, (BYTE*)buffer, strlen(buffer));RegCloseKey(hKey);