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:
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 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.
- To exit the application, press ENTER.
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Â
(http://kbalertz.com/Feedback.aspx?kbNumber=821775/
)
How to enumerate the software products that are installed on a computer