Microsoft KB Archive/914357

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

Article ID: 914357

Article Last Modified on 1/18/2007

-

APPLIES TO


 * Microsoft Visual Studio 2005 Team System Architect Edition
 * Microsoft Visual Studio 2005 Team System Developer Edition
 * Microsoft Visual Studio 2005 Team Foundation
 * Microsoft Visual Studio 2005 Team System Test Edition
 * Microsoft Visual Studio 2005 Standard Edition
 * Microsoft Visual Studio 2005 Professional Edition
 * Microsoft Visual Studio 2005 Express Edition
 * Microsoft Visual Basic 2005

-





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:

256986 Description 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.



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:  Start Microsoft Visual Studio 2005. On the File menu, point to New, and then click Project. 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:

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(&quot;SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall&quot;) 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(&quot;press ENTER to exit&quot;) 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(&quot;SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall&quot;) subkeys = software.GetSubKeyNames

For Each keyname In subkeys Console.WriteLine(keyname) Next

Console.WriteLine(&quot;press ENTER to exit&quot;) Console.ReadLine

End Sub End Module

Step 5: Verify that the code works
 On the Build menu, click Build Solution. On the Debug menu, click Start to run the application.

Note A Console window appears and displays a list of the installed software products.

</li> To exit the application, press ENTER.</li></ol>

<div class="references_section">