WCHAR* Common::getVxInstallPath()
{
HKEY hKey;
LPCWSTR keyPath = L"SOFTWARE\\Tencent\\WeChat";
LONG openResult = RegOpenKeyEx(HKEY_CURRENT_USER, keyPath, 0, KEY_ALL_ACCESS, &hKey);
if (openResult == ERROR_SUCCESS) {
WCHAR valueData[255];
DWORD valueSize = sizeof(valueData);
LONG queryResult = RegQueryValueEx(hKey, L"InstallPath", nullptr, nullptr, (LPBYTE)&valueData, &valueSize);
if (queryResult == ERROR_SUCCESS) {
std::wcout << "WeChat安装路径: " << valueData << std::endl;
RegCloseKey(hKey);
return valueData;
}
else {
::MessageBoxA(NULL, "无法读取注册表值", "提示", MB_OK);
}
}
else {
std::cout << "无法打开注册表键,错误代码: " << openResult << std::endl;
::MessageBoxA(NULL, "无法打开注册表键", "提示", MB_OK);
}
RegCloseKey(hKey);
return NULL;
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/15d7d0ce909f8ae87b0ca41ca31e4a57.png)