Click here to Skip to main content
Click here to Skip to main content

How to list all Programs installed on Computer and Uninstall Them

, 12 Dec 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
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)    Argument temp will tell the uninstaller which product to uninstall, because temp holds the ProductCode.
UninstallProcess.StartInfo.Arguments = temp 


Run the Uninstaller
UninstallProcess.Start() 

           '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..... 

   ' 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

           '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):

' 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)

Share

About the Author

vbCoder21
Software Developer
United States United States
No Biography provided

Comments and Discussions

 
GeneralUninstall Program Code for VB.NET Express Installs PinmemberJustin Spafford7-Jan-11 23:53 
QuestionHow to use the uninstall code with a button Pinmemberdavidz1224-Mar-10 7:54 
QuestionHow to list selected Programs installed on remote Computer PinmemberArulManoj20-Apr-09 21:01 
AnswerRe: How to list selected Programs installed on remote Computer PinmemberCool Cassis2-May-09 1:32 
GeneralRe: How to list selected Programs installed on remote Computer PinmemberHarsimran Singh (.NET)23-Oct-09 10:33 
GeneralRe: How to list selected Programs installed on remote Computer PingroupManiNp23-Mar-10 2:11 
GeneralInstallatin path missing Pinmemberdharmendra Parihar19-Jan-09 20:46 
NewsRe: Installatin path missing PinmemberHarsimran Singh (.NET)4-Feb-09 7:03 
GeneralRe: Installatin path missing Pinmemberdharmendra Parihar4-Feb-09 19:55 
GeneralRe: Installatin path missing PinmemberHarsimran Singh (.NET)23-Oct-09 10:36 
GeneralMy vote of 2 PinmemberUKCodeMonkey15-Dec-08 4:44 
AnswerRe: My vote of 2 PinmemberHarsimran Singh (.NET)15-Dec-08 6:01 
GeneralRe: My vote of 2 PinmemberHarsimran Singh (.NET)23-Oct-09 10:28 
GeneralMy vote of 1 PinmemberAxelM14-Dec-08 21:43 
GeneralMy vote of 1 PinmvpDave Kreskowiak12-Dec-08 4:48 
GeneralRe: My vote of 1 PinmemberHarsimran Singh (.NET)23-Oct-09 10:27 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150414.1 | Last Updated 12 Dec 2008
Article Copyright 2008 by vbCoder21
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid