How to enumerate the software products that are installed on a computer by using the My namespace in Visual Basic 2005

This article has been archived. It is offered "as is" and will no longer be updated.
IMPORTANT : This article contains information about modifying the registry. Before you modify the registry, make sure to back it up and make sure that you understand how to restore the registry if a problem occurs. For information about how to back up, restore, and edit the registry, click the following article number to view the article in the Microsoft Knowledge Base:
256986Description of the Microsoft Windows Registry
INTRODUCTION
This step-by-step article describes how to enumerate the software products that are installed on a computer by using the My namespace in Microsoft Visual Basic 2005. This article also includes sample code that illustrates the concepts that are discussed.

Note To access certain registry keys on a computer, you may have to have administrative credentials.
More information

Requirements

To enumerate software products, you must have the following software installed:
  • Microsoft Windows 2000, Microsoft Windows XP, or Microsoft Windows Server 2003
  • Microsoft Visual Basic 2005
This article assumes that you are familiar with the following topics:
  • Programming with Visual Basic 2005
  • The Windows registry

Step 1: Create a Console Application

To create a new Console Application project by using Visual Studio 2005, follow these steps:
  1. Start Microsoft Visual Studio 2005.
  2. On the File menu, point to New, and then click Project.
  3. Click Visual Basic, click Console Application, type a name for the application, and then click OK.
    Note A new Console Application project is created, and Module1.vb is displayed in Source view.

Step 2: Retrieve a list of installed software products

WARNING : If you use Registry Editor incorrectly, you may cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that you can solve problems that result from using Registry Editor incorrectly. Use Registry Editor at your own risk.

The list of installed software products is located under the following registry subkey:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
To access the list of installed software products, open this registry subkey by adding the following sample code to the Main method.
        Dim hklm As Microsoft.Win32.RegistryKey        Dim software As Microsoft.Win32.RegistryKey        Dim subkeys() As String        Dim keyname As String        hklm = My.Computer.Registry.LocalMachine        software = hklm.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")        subkeys = software.GetSubKeyNames()
Note This code stores a list of installed software products as a string array in the subkeys variable. The keyname variable is used to display the names of these products in step 3.

Step 3: Output the list of installed software products

To output the list of installed products, add the following code to the Main method.
        For Each keyname In subkeys            Console.WriteLine(keyname)        Next

Step 4: Finish the application

To finish the application, add the following code to the Main method.
        Console.WriteLine("press ENTER to exit")        Console.ReadLine()
The complete code listing for Module1.vb is as follows.
Module Module1    Sub Main()        Dim hklm As Microsoft.Win32.RegistryKey        Dim software As Microsoft.Win32.RegistryKey        Dim subkeys() As String        Dim keyname As String        hklm = My.Computer.Registry.LocalMachine        software = hklm.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")        subkeys = software.GetSubKeyNames()        For Each keyname In subkeys            Console.WriteLine(keyname)        Next        Console.WriteLine("press ENTER to exit")        Console.ReadLine()    End SubEnd Module

Step 5: Verify that the code works

  1. On the Build menu, click Build Solution.
  2. On the Debug menu, click Start to run the application.
    Note A Console window appears and displays a list of the installed software products.
  3. To exit the application, press ENTER.
References
For more information about the Windows registry, visit the following Microsoft Developer Network (MSDN) Web site: For more information about how to access the Windows registry by using the My namespace, visit the following MSDN Web site: For more information about how to enumerate the software products that are installed on a computer, click the following article number to view the article in the Microsoft Knowledge Base:
821775 How to enumerate the software products that are installed on a computer
Properties

Article ID: 914357 - Last Review: 01/17/2015 13:22:02 - Revision: 3.0

Microsoft Visual Studio 2005 Standard Edition, Microsoft Visual Studio 2005 Professional Edition, Microsoft Visual Basic 2005

  • kbnosurvey kbarchive kbregistry kbcode kbhowto kbinfo KB914357
Feedback