C++/C读取注册表

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ab1271173712/article/details/75661426

#include "stdafx.h"
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
 HKEY retKey;
 LONG ret;
 char retKeyVal[MAX_PATH * 8] = { 0 };
 DWORD nSize = MAX_PATH * 8;
 string lpVal = "";
 ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\FYglasses", 0, KEY_QUERY_VALUE | KEY_WOW64_32KEY, &retKey);     //此处路径可通过手动先添加到注册表或通过程序写注册表
 if (ret != ERROR_SUCCESS){
  return FALSE;
 }

 //查询键值
 ret = RegQueryValueExA(retKey, "InstallPath", NULL, NULL, (LPBYTE)retKeyVal, &nSize);
 RegCloseKey(retKey);

 if (ret != ERROR_SUCCESS)
 {
  return FALSE;
 }
 lpVal = retKeyVal;
 return 0;
}

C++小程序

猜你喜欢

转载自blog.csdn.net/ab1271173712/article/details/75661426