vs c++ 判断注册表键值是否存在

 

#include "stdafx.h"
#include <windows.h>

int _tmain(int argc, _TCHAR* argv[])
{
 
 //操作注册表
 HKEY key;
 LPBYTE path_Get=new BYTE[254];
 DWORD type =REG_SZ;
 DWORD dwBytes = 254;
 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, KEY_READ, &key) == ERROR_SUCCESS)
    {
  printf("注册表打开成功\n");
        // 查询注册表 值
        if ( RegQueryValueEx(key, _T("hello"), 0, &type, path_Get, &dwBytes ) == ERROR_SUCCESS  )  

    {
       printf("存在\n");
    }
    else
    {
       printf("不存在\n");
    }
  }
 //关闭键
 RegCloseKey(key);
 system("pause");
 return 0;
}

 

 

使用 Unicode 字符集

posted @ 2012-04-28 23:47  神牛  阅读(2810)  评论(0编辑  收藏  举报