H o m e
D e t e r m i n e    I f    A n    A p p l i c a t i o n    I s    I n s t a l l e d

 

By Michael McIntyre

mikemc@getdotnetcode.com

 

You may determine if an application is installed by attempting to open that application’s registry key.

 

The Microsoft.Win32 namespace contains the types necessary to examine registry keys.  To use this namespace add an Imports statement to your code:

 

Imports Microsoft.Win32

 

Below is a sample function that takes a SubKey representing an application as an argument and uses the Microsoft.Win32 Registry Class to attempt to open the application’s SubKey in the ClassesRoot registry hive.  To learn more about the registry hive click here.

 

Function IsApplicationInstalled(ByVal pSubKey As String) As Boolean

   Dim isInstalled As Boolean = False

 

   ' Declare a variable of type RegistryKey named classesRootRegisteryKey.

   ' Assign the Registry's ClassRoot key to the classesRootRegisteryKey variable.

   Dim classesRootRegistryKey As RegistryKey = Registry.ClassesRoot

 

   ' Declare a variable of type RegistryKey named subKeyRegistryKey.

   ' Call classesRootRegistryKey's OpenSubKey method passing in the pSubKey parameter

   ' passed into this function. Assign the result returned to suKeyRegistryKey.

   Dim subKeyRegistryKey As RegistryKey = classesRootRegistryKey.OpenSubKey(pSubKey)

 

   ' If subKeyRegistryKey was assigned a value...

   If Not subKeyRegistryKey Is Nothing Then

   ' Key exists; application is installed.

       isInstalled = True

   End If

 

   ' Close the subKeyRgisteryKey.

   subKeyRegistryKey.Close()

 

   Return isInstalled

End Function

 

Here is a call that uses the function above to determine if Excel is installed:

 

MessageBox.Show("Is MS Excel installed? - " & IsApplicationInstalled("Excel.Application").ToString)

 

RESULT:  Is MS Excell Installed? – True

 

Learn more about the Registry Class by clicking here.

 

Copyright © 2001-2004 aZ Software Developers. All rights reserved.