检查密钥是否已存在(RegOpenKey)
Check if the key already exists (RegOpenKey)
我这样做了:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
HKEY CH;
if(RegCreateKey(HKEY_LOCAL_MACHINE, L"Software\Microsoft\Windows\CurrentVersion\Run",&CH) != 0)
{
printf("Erro - RegCreateKeyn");
system("PAUSE");
return -1;
}
if(RegOpenKey(HKEY_LOCAL_MACHINE, L"Software\Microsoft\Windows\CurrentVersion\Run",&CH) != 0) // Abre a CH "Minha CH"
{
printf("Erro - RegOpenKeyn");
system("PAUSE");
return -1;
}
if(RegSetValueEx(CH,L"PROC",0,REG_SZ,(LPBYTE) L"C:\pasta1\pasta2\txt.txt",200) != 0)
printf("Erro - RegSetValuen");
RegCloseKey(CH);
printf("nsucesso !n");
system("PAUSE");
return 0;
system("PAUSE");
}
现在我想这样做:
if(key already exist) {
//don't make nothing
} else
Create key
...
我需要做什么功能? 因为如果没有,我将创建一个已经存在的密钥。如果我能避免,那就太好了。
使用 RegCreateKeyEx
.如果密钥已存在,它会打开密钥,如果不存在,它会创建密钥。 lpdwDisposition
参数告诉您这两种效果中的哪一种实际发生。 例如:
DWORD disposition = 0;
RegCreateKeyEx(..., &disposition);
if (disposition == REG_CREATED_NEW_KEY) {
/* new key was created */
} else {
/* existing key was opened */
}
相关文章:
- C++模板来检查友元函数的存在
- 既然存在危险,为什么项目要使用-I include开关
- 我们可以访问一个不存在的联盟的成员吗
- C++:对不存在的命名空间使用命名空间指令
- C++quit()函数中可能存在作用域问题
- C++擦除(如果存在)
- g++ 说函数不存在,即使包含正确的标头
- 这个极客对极客的trie实现是否存在内存泄漏问题
- 有了gcc,是否可以链接库,但前提是它存在
- C++LinkedList问题.数据类型之间存在冲突?没有匹配的构造函数
- gcc和clang在表达式是否为常量求值的问题上存在分歧
- C++Builder中的OnClick事件签名存在问题
- 如何正确地将分支添加到已存在的树中
- 我知道函数调用中存在歧义.有没有办法调用foo()函数
- 如何检查QList中是否存在值
- 根据某个函数是否存在启用模板
- 如何将分支添加到已存在的TTree:ROOT
- 地图计数确实很重要,或者只是检查是否存在
- 通用C++/Python 多语言的存在
- 检查密钥是否已存在(RegOpenKey)