A program to display installed applications, VB.net

golfmk2boy

New member
Joined
Jul 7, 2006
Messages
4
Programming Experience
Beginner
Hi,

As in title I need to create a program which will discover the installed applications within windows and then generate an XML file from this. At the moment the key part is discovering the programs which are installed.

Is there any function which can be used within VB to call the installed apps?

Completely new to vb.net, but need to do this as part of a project.

Many thanks.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,603
Location
Norway
Programming Experience
10+
Your best bet is to check the uninstall list in registry LocalMachine\Software\Microsoft\Windows\CurrentVersion\Uninstall. You may also want to exclude some typical items that are not regular applications, like the Hotfixes and Updates. Code below does this, for simplicity just adds each item to a ListBox, when you find the list satisfactory you can write the items to Xml instead.
VB.NET:
Dim regkey, subkey As Microsoft.Win32.RegistryKey
Dim value As String
Dim regpath As String = "Software\Microsoft\Windows\CurrentVersion\Uninstall"
regkey = My.Computer.Registry.LocalMachine.OpenSubKey(regpath)
Dim subkeys() As String = regkey.GetSubKeyNames
Dim includes As Boolean
For Each subk As String In subkeys
  subkey = regkey.OpenSubKey(subk)
  value = subkey.GetValue("DisplayName", "")
  If value <> "" Then
    includes = True
    If value.IndexOf("Hotfix") <> -1 Then includes = False
    If value.IndexOf("Security Update") <> -1 Then includes = False
    If value.IndexOf("Update for") <> -1 Then includes = False
    If includes = True Then ListBox1.Items.Add(value)
  End If
Next
You perhaps also want to remove some parts of string like "(remove only)", this is simple string manipulation of the value variable in the example.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,603
Location
Norway
Programming Experience
10+
I just remembered something, some applications are only installed for current user, so you have check same registry path as with LocalMachine for CurrentUser too. All the same code but:
VB.NET:
regkey = My.Computer.Registry.[COLOR=darkgreen]CurrentUser[/COLOR].OpenSubKey(regpath)
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,603
Location
Norway
Programming Experience
10+
A while since this was up, try also WMI and Win32_Product class. I just posted a tip about a free tool that generates WMI code. Here is example in this case:
VB.NET:
Imports System
Imports System.Management
Imports System.Windows.Forms
Namespace WMISample
    Public Class MyWMIQuery
        Public Overloads Shared Function Main() As Integer
            Try
                Dim searcher As New ManagementObjectSearcher( _
                    "root\CIMV2", _
                    "SELECT * FROM Win32_Product") 
                Console.WriteLine("-----------------------------------")
                Console.WriteLine("Win32_Product instance")
                Console.WriteLine("-----------------------------------")
                For Each queryObj As ManagementObject in searcher.Get()
                    Console.WriteLine("Name: {0}", queryObj("Name"))
                Next
            Catch err As ManagementException
                MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
            End Try
        End Function
    End Class
End Namespace
 
Top Bottom