coderluan
2023-03-29 10:50:35 +08:00
HKEY hKey;
TCHAR szPath[MAX_PATH];
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
{
TCHAR szSubKey[MAX_PATH];
DWORD dwSubKeyLen = sizeof(szSubKey);
for (DWORD i = 0; RegEnumKeyEx(hKey, i, szSubKey, &dwSubKeyLen, NULL, NULL, NULL, NULL) != ERROR_NO_MORE_ITEMS; i++, dwSubKeyLen = sizeof(szSubKey))
{
HKEY hSubKey;
if (RegOpenKeyEx(hKey, szSubKey, 0, KEY_READ, &hSubKey) == ERROR_SUCCESS)
{
TCHAR szValue[MAX_PATH];
DWORD dwValueLen = sizeof(szValue);
if (RegQueryValueEx(hSubKey, L"DisplayName", NULL, NULL, (LPBYTE)szValue, &dwValueLen) == ERROR_SUCCESS)
{
if (_wcsicmp(szValue, L"Program Name") == 0) // 替换成要查询的程序名称
{
dwValueLen = sizeof(szValue);
if (RegQueryValueEx(hSubKey, L"InstallLocation", NULL, NULL, (LPBYTE)szValue, &dwValueLen) == ERROR_SUCCESS)
{
wcsncpy_s(szPath, MAX_PATH, szValue, MAX_PATH);
break;
}
}
}
RegCloseKey(hSubKey);
}
}
RegCloseKey(hKey);
}