读书人

注册表不能添加键,该怎么解决

发布时间: 2012-03-12 12:45:33 作者: rapoo

注册表不能添加键
用C++调用WINDOWS API:RegCreateKeyEx、RegSetValueEx在注册表中增加子键以及键值。函数执行结束后未看到新键值。代码如下:

C/C++ code
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);

MSDN上有句话:An application cannot create a key that is a direct child of HKEY_USERS or HKEY_LOCAL_MACHINE. An application can create subkeys in lower levels of the HKEY_USERS or HKEY_LOCAL_MACHINE trees.
怀疑是由于进程权限不够,不能在HKEY_USERS or HKEY_LOCAL_MACHINE创建子键,在HKEY_CURRENT_USER键下可以创建……

在线求解!

[解决办法]
楼主是否开了360,如果开了把360关了在试试

读书人网 >C++

热点推荐