Microsoft Knowledge Base Email Alertz

KBAlertz.com: (914357) - Describes how to enumerate the software products that are installed on a computer by using Microsoft Visual Basic 2005 and the Windows registry. Sample code is provided.

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
KBAlertz referrals get
** SIX MONTHS FREE **


Community Site



We Send hundreds of thousands of emails using ASP.NET Email


ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 914357 - Last Review: January 18, 2007 - Revision: 2.0

How to enumerate the software products that are installed on a computer by using the My namespace in 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  (http://kbalertz.com/Feedback.aspx?kbNumber=256986/EN-US/ ) Description of the Microsoft Windows Registry

On This Page

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 Sub
End 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:
http://msdn2.microsoft.com/en-us/library/aa370338.aspx (http://msdn2.microsoft.com/en-us/library/aa370338.aspx)
For more information about how to access the Windows registry by using the My namespace, visit the following MSDN Web site:
http://msdn2.microsoft.com/en-us/library/0wc4y85e(VS.80).aspx (http://msdn2.microsoft.com/en-us/library/0wc4y85e(VS.80).aspx)
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

APPLIES TO
  • Microsoft Visual Studio 2005 Team System Architect Edition
  • Microsoft Visual Studio 2005 Team Foundation
  • Microsoft Visual Studio 2005 Standard Edition
  • Microsoft Visual Studio 2005 Professional Edition
  • Microsoft Visual Basic 2005
Keywords: 
kbregistry kbcode kbhowto kbinfo KB914357
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Anonymous User Report As Irrelevant  
Written: 1/5/2007 11:00 PM
hi the code you gave was good but how can the same code be used in a window application and how can the the output values generated within a string array

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please