Click here to Skip to main content
15,867,594 members
Articles / Programming Languages / Visual Basic
Article

How to list all Programs installed on Computer and Uninstall Them

Rate me:
Please Sign up or sign in to vote.
3.37/5 (10 votes)
12 Dec 2008CPOL5 min read 265K   21   16
List and Uninstall ALL Programs installed in the Client's Computer.

Download - Source Code (VB .NET)

Introduction 

This article will teach you how to List All the installed Software from your computer and their information. This article will also explain you how to uninstall a Software.

Requirements:

  1. Namespace "Microsoft.Win32"
  2. Knowledge of the Registry.
  3. Namespace "System.Diagnostics"
Features:
  1. List all Software installed on Client Machine.
  2. List all Software Information.
  3. Uninstall a Software.
We hope you enjoy this Article!!!!

Understanding and Using the Registry

The Registry Key is really the KEY here to getting this job done.

Terms to understand:

  1. When I refer to OLD, I mean that the OLD Registry key provided by some online Resources.
  2. Referring to NEW, means the Registry Key used in this article and Program Uninstaller.

Where the Registry Key is and How is differs from other Developers.

Well, before I created this application, I really did not have any clue about where what was and how it all worked. I searched online and found a few resources. These resources helped me list SOME installed Software, not all. I figured this out by comparing the Programs and Features in Vista (Add or Remove Programs in XP). There was a HUGE different. My OLD list was not even close to having the number of Programs listed in Programs and Features. So I decided to search for new Registry Keys. I discovered two keys, I key just had five software, the other had almost the same number of Software discovered in Programs and Features. I will now tell you the online resources Registry Key and the Registry key used in this article.

  • Online Resources Registry Key:
  • Registry Key used in this article: "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products" This is from the LocalMachine
The Registry Key used in this article returns something like the image below from the Registry:

The Software Information in the Key.

The following image shows all the Keys that have Software Information. After opening that one key, there are four different keys found that will have the Software information:


We will be using the "InstallProperties" key, because that has the Information the user could understand. The InstallProperties key will return something like the image below:

From the image below, I will explain to you what key and its data means. I will only explain the key's that are important to know.

Contact: Who to contact for support.
Display Name:  The name of the Software.
Display Version:  The version of the software.
Estimated Size:   The size of the software.  (You need to convert this to an   Integer, so the User can understand it)
Help Link: Link to visit for help.
Help Telephone: Help Telephone Number.
Installed Date: The date this Software was installed.   
Install Location: The Installation Location.
Install Source: The Installation Directory.
Language: Languages supported by this Software.
Local Package: The MSI File Location.
ModifyPath: The string returned here looks something like this: MsiExec.exe /I{AC76BA86-7AD7-1033-7B44-A81200000003}
            I will explain this to you more in a section in this article.
Publisher: The publisher of the Software.
Readme: The location of the readme file for this software.
UninstallString: The uninstallString returns a value similar to ModifyPath.  I will explain more about this later on.
URLInfoAbout: The URL to visit for more information on the Product.
URLUpdateInfo: The url to visit for updates information.
Version: Version of the Software.

Product Uninstall:  What the heck is MsiExec.exe /I{AC76BA86-7AD7-1033-7B44-A81200000003}? 

That is what I said when I first saw this string.  I did some research on this.  And what really helped me out was the Microsoft TechNet Website.  http://technet.microsoft.com/en-us/library/bb490936.aspx

 The following will teach you about the Syntax and other Parameters that you can use.

Syntax 

msiexec /f [p][o][e][d][c][a][u][m][s][v]{package|ProductCode}

Parameters 

/f   : Enables one or more of the command-line options listed in the following table.

Command

Description

p

Reinstalls only if file is missing.

o

Reinstalls if file is missing or if an older version is installed.

e

Reinstalls if file is missing or an equal or older version is installed.

d

Reinstalls if file is missing or a different version is installed.

c

Reinstalls if file is missing or the stored checksum does not match the calculated value.

a

Forces all files to be reinstalled.

u

Rewrite all required user-specific registry entries.

m

Rewrites all required computer-specific registry entries.

s

Overwrites all existing shortcuts.

v

Runs from source and re-caches the local package.

package   : Name of the Windows Installer package file.

ProductCode   : Globally unique identifier (GUID) of the Windows Installer package.

You can use msiexec and any of the commands shown above to perform the operation.  

Uninstalling a Product.

Variables to Decalre:

  • String uninstallString - String that will hold the UninstallString for the Product to Uninstall
  • Process UninstallProcess -  Process that will run the Uninstallation.
  • String temp - Hold the part 2 of the UninstallString.  
             Part 1: MsiExec.exe
             Part 2: /I{AC76BA86-7AD7-1033-7B44-A81200000003}

The "UninstallProcess".......How it all works......

The split makes the filename MsiExec.exe.  This will run the Microsoft Installer.
UninstallProcess.StartInfo.FileName = _ uninstallstring.Split("/".ToCharArray)(0)  <code><code><code><code><code>  Argument temp will tell the uninstaller which product to uninstall, because temp holds the ProductCode.
UninstallProcess.StartInfo.Arguments = temp 


Run the Uninstaller
UninstallProcess.Start() 

VB.NET
'UninstallProductname should hold the UninstallString from the Registry
 Dim uninstallString as string
 Dim UninstallProcess As New System.Diagnostics.Process()
 'temp will hold something like this:  /I{AC76BA86-7AD7-1033-7B44-A81200000003}
 Dim temp As String = uninstallstring.Substring(12)
'replacing with /x with /i would cause another popup of the application uninstall
'The FileName will be: MsiExec.exe
 UninstallProcess.StartInfo.FileName = uninstallstring.Split("/".ToCharArray)(0)
 UninstallProcess.StartInfo.Arguments = temp
 UninstallProcess.Start()

 Listing all the Software Installed..... 

VB.NET
   ' HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products
        Dim Software As String = Nothing
        'The registry key will be held in a string SoftwareKey.
        Dim SoftwareKey As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products"
        Using rk As RegistryKey = Registry.LocalMachine.OpenSubKey(SoftwareKey)
            For Each skName In rk.GetSubKeyNames
                'Get sub keys
                Dim name = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("DisplayName")
                'Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("DisplayName")
                Dim installocation = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("InstallLocation")
                'InstallProperties
                Dim publisher = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("Publisher")
                Dim uninstallString = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("UninstallString")
                'Add the Software information to lstPrograms
                If name.ToString <> "" Then
                    'Declare new ListView Item
                    Dim list As New ListViewItem
                    'Set Text Property to Name of Software
                    list.Text = name.ToString
                    'Add Install Location
                    list.SubItems.Add(installocation.ToString)
                    'Add Publisher
                    list.SubItems.Add(publisher.ToString)
                    ' Add it to lstPrograms, a listview that will hold our Software List.
                    lstPrograms.Items.Add(list)
                End If
                'next
            Next
        End Using  

 

All Source Code:

Uninstalling a Software

VB.NET
'UninstallProductname should hold the UninstallString from the Registry
 Dim uninstallString as string


 Dim UninstallProcess As New System.Diagnostics.Process()
'temp will hold something like this:  /I{AC76BA86-7AD7-1033-7B44-A81200000003}
 Dim temp As String = uninstallstring.Substring(12)
'replacing with /x with /i would cause another popup of the application uninstall

'The FileName will be: MsiExec.exe
 UninstallProcess.StartInfo.FileName = uninstallstring.Split("/".ToCharArray)(0)
 UninstallProcess.StartInfo.Arguments = temp
 UninstallProcess.Start() 

Listing all Software into a Listview (lstPrograms):

VB.NET
' HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products
        Dim Software As String = Nothing
        'The registry key will be held in a string SoftwareKey.
        Dim SoftwareKey As String = "SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products"
        Using rk As RegistryKey = Registry.LocalMachine.OpenSubKey(SoftwareKey)
            For Each skName In rk.GetSubKeyNames
                'Get sub keys
                Dim name = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("DisplayName")
                'Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("DisplayName")
                Dim installocation = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("InstallLocation")
                'InstallProperties
                Dim publisher = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("Publisher")
                Dim uninstallString = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("UninstallString")
                'Add the Software information to lstPrograms
                If name.ToString <> "" Then
                    'Declare new ListView Item
                    Dim list As New ListViewItem
                    'Set Text Property to Name of Software
                    list.Text = name.ToString
                    'Add Install Location
                    list.SubItems.Add(installocation.ToString)
                    'Add Publisher
                    list.SubItems.Add(publisher.ToString)
                    ' Add it to lstPrograms, a listview that will hold our Software List.
                    lstPrograms.Items.Add(list)
                End If
                'next
            Next
        End Using  
 

Conclusion

This application is a great way for Developers to interact with the Windows API and the Registry.  You also get to learn how some calls are made in the Windows Environment.  I really hope to see Developers using techniques shown in this article in their Applications.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralUninstall Program Code for VB.NET Express Installs Pin
Justin Spafford7-Jan-11 22:53
Justin Spafford7-Jan-11 22:53 
'Some were in this code you need to send the uninstall
'information to the computer if you intend to uninstall
'your program or the code as is listing to a ListView1 control
'I thank the coder for posting this information
ListView1.Items.Clear()
Dim InstalledSoftwareKey As String = "Software\Microsoft\Windows\CurrentVersion\Uninstall\"
Using rkArray As RegistryKey = Registry.CurrentUser.OpenSubKey(InstalledSoftwareKey)
For Each rkArrayName In rkArray.GetSubKeyNames
Dim rkArrayKey = "HKEY_CURRENT_USER\" & InstalledSoftwareKey & rkArrayName
Dim DisplayName = My.Computer.Registry.GetValue(rkArrayKey, "DisplayName", "NA")
Dim DisplayVersion = My.Computer.Registry.GetValue(rkArrayKey, "DisplayVersion", "NA")
Dim UninstallString = My.Computer.Registry.GetValue(rkArrayKey, "UninstallString", "NA")
If DisplayName.ToString <> "" Then
Dim rkArrayList As New ListViewItem
rkArrayList.Text = DisplayName.ToString
rkArrayList.SubItems.Add(DisplayVersion.ToString)
rkArrayList.SubItems.Add(UninstallString.ToString)
ListView1.Items.Add(rkArrayList)
End If
Next
End Using
QuestionHow to use the uninstall code with a button Pin
davidz1224-Mar-10 6:54
davidz1224-Mar-10 6:54 
QuestionHow to list selected Programs installed on remote Computer Pin
ArulManoj20-Apr-09 20:01
ArulManoj20-Apr-09 20:01 
AnswerRe: How to list selected Programs installed on remote Computer Pin
Cool Cassis2-May-09 0:32
Cool Cassis2-May-09 0:32 
GeneralRe: How to list selected Programs installed on remote Computer Pin
vbCoder2123-Oct-09 9:33
vbCoder2123-Oct-09 9:33 
GeneralRe: How to list selected Programs installed on remote Computer Pin
ManiNp23-Mar-10 1:11
ManiNp23-Mar-10 1:11 
GeneralInstallatin path missing Pin
dharmendra Parihar19-Jan-09 19:46
dharmendra Parihar19-Jan-09 19:46 
NewsRe: Installatin path missing Pin
vbCoder214-Feb-09 6:03
vbCoder214-Feb-09 6:03 
GeneralRe: Installatin path missing Pin
dharmendra Parihar4-Feb-09 18:55
dharmendra Parihar4-Feb-09 18:55 
GeneralRe: Installatin path missing Pin
vbCoder2123-Oct-09 9:36
vbCoder2123-Oct-09 9:36 
GeneralMy vote of 2 Pin
jlwarlow15-Dec-08 3:44
jlwarlow15-Dec-08 3:44 
AnswerRe: My vote of 2 Pin
vbCoder2115-Dec-08 5:01
vbCoder2115-Dec-08 5:01 
GeneralRe: My vote of 2 Pin
vbCoder2123-Oct-09 9:28
vbCoder2123-Oct-09 9:28 
GeneralMy vote of 1 Pin
AxelM14-Dec-08 20:43
AxelM14-Dec-08 20:43 
GeneralMy vote of 1 Pin
Dave Kreskowiak12-Dec-08 3:48
mveDave Kreskowiak12-Dec-08 3:48 
GeneralRe: My vote of 1 Pin
vbCoder2123-Oct-09 9:27
vbCoder2123-Oct-09 9:27 

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.