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:
- Namespace "Microsoft.Win32"
- Knowledge of the Registry.
- Namespace "System.Diagnostics"
Features:
- List all Software installed on Client Machine.
- List all Software Information.
- 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:
- When I refer to OLD, I mean that the OLD Registry key provided by some online Resources.
- 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 UninstallProcess 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()
Dim uninstallString as string
Dim UninstallProcess As New System.Diagnostics.Process()
Dim temp As String = uninstallstring.Substring(12)
UninstallProcess.StartInfo.FileName = uninstallstring.Split("/".ToCharArray)(0)
UninstallProcess.StartInfo.Arguments = temp
UninstallProcess.Start()
Listing all the Software Installed.....
Dim Software As String = Nothing
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
Dim name = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("DisplayName")
Dim installocation = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("InstallLocation")
Dim publisher = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("Publisher")
Dim uninstallString = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("UninstallString")
If name.ToString <> "" Then
Dim list As New ListViewItem
list.Text = name.ToString
list.SubItems.Add(installocation.ToString)
list.SubItems.Add(publisher.ToString)
lstPrograms.Items.Add(list)
End If
Next
End Using
All Source Code:
Uninstalling a Software
Dim uninstallString as string
Dim UninstallProcess As New System.Diagnostics.Process()
Dim temp As String = uninstallstring.Substring(12)
UninstallProcess.StartInfo.FileName = uninstallstring.Split("/".ToCharArray)(0)
UninstallProcess.StartInfo.Arguments = temp
UninstallProcess.Start()
Listing all Software into a Listview (lstPrograms):
Dim Software As String = Nothing
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
Dim name = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("DisplayName")
Dim installocation = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("InstallLocation")
Dim publisher = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("Publisher")
Dim uninstallString = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skName).OpenSubKey("InstallProperties").GetValue("UninstallString")
If name.ToString <> "" Then
Dim list As New ListViewItem
list.Text = name.ToString
list.SubItems.Add(installocation.ToString)
list.SubItems.Add(publisher.ToString)
lstPrograms.Items.Add(list)
End If
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.