find application in Registry?

CoachBarker

Well-known member
Joined
Jul 26, 2007
Messages
133
Programming Experience
1-3
How would you go about through code to find out if an application is in the registry.
:confused:
Thanks
Coach Barker
 
This article may help you in accessing registry http://www.codeproject.com/vb/net/registry_with_vb.asp.

Instead of using registry better use WMI. You may also check WMICodeCreator. Also check the Win32_Product class.

example code for enumerating installed applications using WMI is as follows.

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") 

                For Each queryObj As ManagementObject in searcher.Get()

                    Console.WriteLine("-----------------------------------")
                    Console.WriteLine("Win32_Product instance")
                    Console.WriteLine("-----------------------------------")
                    Console.WriteLine("Caption: {0}", queryObj("Caption"))
                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
 
This quick example will show all the installed softwares

VB.NET:
Imports Microsoft.Win32

VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim mainKey As RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
        Dim subKeys() As String = mainKey.GetSubKeyNames()
        Dim currentKey As RegistryKey
        Dim installedSoftwares As String
        For Each subKey As String In subKeys
            currentKey = mainKey.OpenSubKey(subKey, False)
            Dim displayName As String = currentKey.GetValue("DisplayName")
            If Not displayName = String.Empty Then
                installedSoftwares &= displayName & Environment.NewLine
            End If
        Next
        MessageBox.Show(installedSoftwares)
    End Sub
 
Then how about if I want to look for one specific software application and return a true or false if it is installed or not?:eek:
 
VB.NET:
Imports Microsoft.Win32

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim appName As String = "Microsoft Sql Server 2005"
        If Find(appName) Then
            MessageBox.Show(appName & " is installed!")
        Else
            MessageBox.Show(appName & " is not installed!!")
        End If
    End Sub

    Public Function Find(ByVal appName As String) As Boolean
        Dim mainKey As RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")
        Dim subKeys() As String = mainKey.GetSubKeyNames()
        Dim currentKey As RegistryKey
        For Each subKey As String In subKeys
            currentKey = mainKey.OpenSubKey(subKey, False)
            Dim displayName As String = currentKey.GetValue("DisplayName")
            If Not String.IsNullOrEmpty(displayName) Then
                If displayName.ToLower() = appName.ToLower() Then
                    Return True
                End If
            End If
        Next
        Return False
    End Function
End Class

Also check for CurrentUser Also.
 
Thank you very much that is pretty much what I needed, I see the logic behind
Dim mainKey As RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Uninstall")

If the application is installed then it has to be able to be uninstalled. :)
 
In the registry the only place my application is listed is here

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Connection Manager\Xxxxxxxxx University VPN
when I try to do

Dim mainKey As RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Connection Manager")

and then the button click event

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim appName As String = "Xxxxxxxxx University VPN
"
If CheckVPN(appName) Then
MessageBox.Show(appName & " is installed!")
Else
MessageBox.Show(appName & " is not installed!!")
End If
End Sub

I get the " is not installed!!" messgae.
Any ideas as to why?
 
I figured out the problem. When the VPN is installed it only creates in the registry a folder called Onnection Manager, so insteac of looking for the VPN I only had to look for the folder.

Thanks for your help
Coach Barker:)
 
Back
Top