Click here to Skip to main content
15,881,089 members
Articles / Desktop Programming / WTL
Article

How to get a list of installed applications

Rate me:
Please Sign up or sign in to vote.
4.66/5 (26 votes)
20 Apr 20041 min read 211.9K   8.9K   68   24
Duplicate the list seen in the Add/Remove Programs Control Panel applet.

Sample screenshot

Introduction

Recently, I answered a question in the Visual C++ Forum concerning how you would duplicate the list of installed programs seen when you select Add/Remove Programs in Control Panel, and I thought the solution would make a nice (if basic) article.

To fetch the list is very easy - first you need to open the following registry key:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall

Then simply enumerate all the entries and fetch the DisplayName value from each one.

MFC/WTL/ATL

In order to cater for all tastes, I have included versions of my code for the following environments:

  • MFC
  • WTL
  • ATL7 (included with Visual Studio 2002/2003)

The differences between the MFC and WTL versions are subtle - the MFC version stores the list of programs in a CStringArray and the WTL version uses a CSimpleArray<CString>.

The ATL7 version makes use the of the handy CRegKey class.

Using the CInstalledSoftware Class

To use this class, simply declare an instance of the CInstalledSoftware class in your application, and the constructor will fill the public m_aPrograms member with the list of installed programs. For example, to fill an MFC listbox, you may have code like this:

CInstalledSoftware apps;
for (int i = 0; i < apps.m_aPrograms.GetCount(); i++)
    m_wndList.AddString(apps.m_aPrograms[i]);

That's it! Rocket science it ain't!

Building the List - MFC/WTL

The MFC/WTL versions of the code build the list using Win32 registry calls:

void BuildList(void)
{
  HKEY hKey;
  if (::RegOpenKeyEx(HKEY_LOCAL_MACHINE, IS_KEY, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
   return;

  DWORD dwIndex = 0;
  LONG lRet;
  DWORD cbName = IS_KEY_LEN;
  TCHAR szSubKeyName[IS_KEY_LEN];

  while ((lRet = ::RegEnumKeyEx(hKey, dwIndex, szSubKeyName, &cbName, NULL,
   NULL, NULL, NULL)) != ERROR_NO_MORE_ITEMS)
  {
   // Do we have a key to open?
   if (lRet == ERROR_SUCCESS)
   {
    // Open the key and get the value
    HKEY hItem;
    if (::RegOpenKeyEx(hKey, szSubKeyName, 0, KEY_READ, &hItem) != ERROR_SUCCESS)
     continue;
    // Opened - look for "DisplayName"
    TCHAR szDisplayName[IS_KEY_LEN];
    DWORD dwSize = sizeof(szDisplayName);
    DWORD dwType;

    if (::RegQueryValueEx(hItem, IS_DISPLAY, NULL, &dwType,
     (LPBYTE)&szDisplayName, &dwSize) == ERROR_SUCCESS)
    {
     // Add to the main array
     m_aPrograms.Add(szDisplayName);
    }
    ::RegCloseKey(hItem);
   }
   dwIndex++;
   cbName = IS_KEY_LEN;
  }
  ::RegCloseKey(hKey);
 }

The ATL7 version uses the much more readable CRegKey class:

void BuildList(void)
{
 CRegKey reg;
 if (reg.Open(HKEY_LOCAL_MACHINE, IS_KEY, KEY_READ) != ERROR_SUCCESS)
  return;

 DWORD dwIndex = 0;
 DWORD cbName = IS_KEY_LEN;
 TCHAR szSubKeyName[IS_KEY_LEN];
 LONG lRet;

 while ((lRet = reg.EnumKey(dwIndex, szSubKeyName, &cbName)) != ERROR_NO_MORE_ITEMS)
 {
  if (lRet == ERROR_SUCCESS)
  {
   CRegKey regItem;
   if (regItem.Open(reg, szSubKeyName, KEY_READ) == ERROR_SUCCESS)
   {
    // Get the "DisplayName" value
    ULONG ulChars;
    if (regItem.QueryStringValue(IS_DISPLAY, NULL, &ulChars) == ERROR_SUCCESS)
    {
     CString strName;
     regItem.QueryStringValue(IS_DISPLAY, strName.GetBuffer(ulChars), &ulChars);
     strName.ReleaseBuffer();
     // Add to the array
     m_aPrograms.Add(strName);
    }
   }
  }
  dwIndex++;
  cbName = IS_KEY_LEN;
 }
}

OK, this class isn't going to win any prizes, but hopefully others will find it useful. Comments welcome!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here



Comments and Discussions

 
QuestionHow to give the access to the particular application Pin
Member 92748641-Aug-12 17:32
Member 92748641-Aug-12 17:32 
QuestionRE: How to get list of all d softwares installed in ur pc using a java programing language Pin
PrakashReddy jalla3-Apr-12 20:57
PrakashReddy jalla3-Apr-12 20:57 
Generalu missed some issues ---> Pin
mr.baby1231-Sep-10 1:30
mr.baby1231-Sep-10 1:30 
GeneralWhich part of Registry to Read? for last time used of a software Pin
Cheng XUAN26-Oct-09 16:41
Cheng XUAN26-Oct-09 16:41 
GeneralTo do it with program paths Pin
dc_200027-Sep-09 11:51
dc_200027-Sep-09 11:51 
GeneralC# Version Pin
Blue36516-Aug-09 0:41
Blue36516-Aug-09 0:41 
GeneralWant same for hardware(devices) Pin
Omkar Somani8-Jul-08 23:55
Omkar Somani8-Jul-08 23:55 
Smile | :) Hi the code is really nice.
can you just provide the source code for this and also can we do same for devices.
QuestionHow can i export the data from the installed_programs_wtl_atl7.exe to a .txt Pin
Meleneky17-Jul-07 13:19
Meleneky17-Jul-07 13:19 
QuestionHow to get list of installed software in file using fwrite Pin
Vinamrata16-Jul-07 19:25
Vinamrata16-Jul-07 19:25 
GeneralOnly half works on a non-32-bit OS... Pin
etheriau1-May-07 20:16
etheriau1-May-07 20:16 
GeneralExcellent information Pin
NetDave26-Apr-07 10:49
NetDave26-Apr-07 10:49 
Generalwant know icon of installed program Pin
chenxuri6-Jul-06 15:37
chenxuri6-Jul-06 15:37 
GeneralRe: want know icon of installed program Pin
Nibu babu thomas4-Oct-06 22:56
Nibu babu thomas4-Oct-06 22:56 
GeneralWant to know path of .exe file Pin
pitnu2-Dec-05 23:24
pitnu2-Dec-05 23:24 
GeneralRe: Want to know path of .exe file Pin
han qiao6-Mar-07 15:56
han qiao6-Mar-07 15:56 
GeneralFrequency of Use Pin
Chamank1-Sep-05 0:39
Chamank1-Sep-05 0:39 
GeneralProgram full path Pin
junhee26-Apr-05 22:06
professionaljunhee26-Apr-05 22:06 
QuestionHow to get a list of installed applications Pin
krishnan@fastermail.com23-Sep-04 19:04
krishnan@fastermail.com23-Sep-04 19:04 
AnswerRe: How to get a list of installed applications Pin
David Crow18-Nov-08 7:50
David Crow18-Nov-08 7:50 
GeneralRe: How to get a list of installed applications Pin
Charles Oppermann4-Aug-11 11:23
Charles Oppermann4-Aug-11 11:23 
GeneralRe: How to get a list of installed applications Pin
David Crow7-Aug-11 19:06
David Crow7-Aug-11 19:06 
QuestionHow to determine whether there is any application exist with a file extension Pin
KmAshif5-Jun-04 18:10
KmAshif5-Jun-04 18:10 
AnswerRe: How to determine whether there is any application exist with a file extension Pin
Jonathan Hodgson15-Jun-04 5:21
Jonathan Hodgson15-Jun-04 5:21 
GeneralDoesn't handle MSI based Installers Well Pin
dbareis30-Apr-04 16:35
dbareis30-Apr-04 16:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.