How do I list all programs installed on my computer? I've tried using the MsiEnumProducts
and MsiGetProductInfo
functions, but they do not return a full list of installed applications like I see in "Add/Remove Programs".
Asked
Active
Viewed 1.1k times
5
1 Answers
10
Enumerate the registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
bool EnumInstalledSoftware(void)
{
HKEY hUninstKey = NULL;
HKEY hAppKey = NULL;
WCHAR sAppKeyName[1024];
WCHAR sSubKey[1024];
WCHAR sDisplayName[1024];
WCHAR *sRoot = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
long lResult = ERROR_SUCCESS;
DWORD dwType = KEY_ALL_ACCESS;
DWORD dwBufferSize = 0;
//Open the "Uninstall" key.
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, sRoot, 0, KEY_READ, &hUninstKey) != ERROR_SUCCESS)
{
return false;
}
for(DWORD dwIndex = 0; lResult == ERROR_SUCCESS; dwIndex++)
{
//Enumerate all sub keys...
dwBufferSize = sizeof(sAppKeyName);
if((lResult = RegEnumKeyEx(hUninstKey, dwIndex, sAppKeyName,
&dwBufferSize, NULL, NULL, NULL, NULL)) == ERROR_SUCCESS)
{
//Open the sub key.
wsprintf(sSubKey, L"%s\\%s", sRoot, sAppKeyName);
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, sSubKey, 0, KEY_READ, &hAppKey) != ERROR_SUCCESS)
{
RegCloseKey(hAppKey);
RegCloseKey(hUninstKey);
return false;
}
//Get the display name value from the application's sub key.
dwBufferSize = sizeof(sDisplayName);
if(RegQueryValueEx(hAppKey, L"DisplayName", NULL,
&dwType, (unsigned char*)sDisplayName, &dwBufferSize) == ERROR_SUCCESS)
{
wprintf(L"%s\n", sDisplayName);
}
else{
//Display name value doe not exist, this application was probably uninstalled.
}
RegCloseKey(hAppKey);
}
}
RegCloseKey(hUninstKey);
return true;
}

NTDLS
- 4,757
- 4
- 44
- 70
-
Just to add for anyone seeing this and experiencing errors, you need to enable Unicode in your Project Properties: under Configuration Properties and General, change the parameter Character Set to Use Unicode Character Set. – Darius Jun 23 '14 at 21:58
-
It's funny because I never develop Unicode C++. I did just this once for this example because I figured I would be berated if I didn't. :) – NTDLS Jun 27 '14 at 18:24
-
What about the installation date? – Michael Haephrati Dec 07 '14 at 20:28
-
2In more modern versions of Windows, it seems that the vast majority of programs can actually be found in "SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall". The path given in this answers only holds very few programs for me. – TheSHEEEP Nov 22 '18 at 10:19
-
1@TheSHEEEP That's a good point! Any program 32-bit or 64-bit should check for the existence of and enumerate both registry keys. – NTDLS Nov 26 '18 at 17:17