现在需要写一个启动器,要去获取一个安装了的软件的位置,并且加上启动参数启动。写入快捷方式不行,因为软件升级会重新恢复快捷方式。 获取 windows 下安装软件的位置有什么好的方法没有? 启动器, Windows, 软件, 快捷
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); }