c++ - 如何使用 RegOpenKeyEx 创建或查询注册表

标签 c++ c registry

我想写入一个注册表值

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);

enter image description here

最佳答案

这个 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/

相关文章:

c++ - RegOpenKeyEx() 返回 ERROR_ACCESS_DENIED

c++ - C++中的链表数组

c++ - 模板父类(super class)的静态成员定义

c - 循环遍历数据文件末尾

windows - OEM数据的含义

installation - WIX 使用 x86 安装程序安装 x64 组件?

c++ - 如何在 XCode 中创建多个控制台窗口

c++ - 相同大小的小对象的非常快速的对象分配器

c - 使用 keyfromString 函数切换字符串的大小写

c - 分配给结构成员的值不正确