我想写入一个注册表值
HKEY_CURRENT_USER\Software\Adobe\Acrobat Reader\11.0\Identity => key = tName , value="user1"
但每次我得到 "RegOpenKeyEx SOFTWARE\Adobe\Acrobat Reader\11.0\Identity failed (error=2) "
因为错误表明身份 key 不存在于注册表中。
如果注册表不存在,如何创建它。 如果 key 不存在,我想创建并打开它,注册表就在那里。
lStat = RegOpenKeyEx( HKEY_CURRENT_USER, /*handle of open key */
szSubKey, /* address of name of subkey to open */
0, /* reserved */
KEY_READ , /* security access mask */
&hKey /* address of handle of open key */
);
if ( lStat != ERROR_SUCCESS) {
sprintf(szMsg,"RegOpenKeyEx %s failed (error=%ld) ",
szSubKey, lStat);
traceMsg(szMsg);
return lStat;
}
lStat = RegSetValueEx(hKey,(LPCTSTR)szValue, NULL, &Type,
(LPBYTE)szUser, strlen(szUser)+1);
最佳答案
这个 key 存在吗? MSDN:
Unlike the RegCreateKeyEx function, the RegOpenKeyEx function does not create the specified key if the key does not exist in the registry.
首先尝试 regedit
。
其次,您指定KEY_READ
,然后想写点东西。
关于c++ - 如何使用 RegOpenKeyEx 创建或查询注册表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41115433/