Need some way to test if Bartender is installed Follow


I am developing an app which uses your .NET SDK. So far so good,


What I'd like is some means of testing if Bartender is installed, so that my app can feedback to the user that this part of the overall functionality is unavailable. Possibilities:

1) Use Type.GetTypeFromProgID() to check for a COM class, e.g.:

    Public Shared Function IsInstalled() As Boolean
        Return Type.GetTypeFromProgID("BarTender.Application") IsNot Nothing
    End Function

2) Look through the filesystem for installed folders/files.


I don't much like either of those options. The first relies on COM (ugh), and the second relies on Seagull keeping the filesystem consistent over future versions. I can't use an existing .NET method, because chicken/egg etc.


What's the solution? If all else fails, could we be provided with a redistributable DLL which Seagull supports and allows this test?


Ian Dyer
Comment actions Permalink

EDIT: After some testing, I found that the above does not work if Bartender is uninstalled, because the uninstaller does not properly clean up its registry. Specifically, it leaves the BarTender.Application class behind in HKEY_CLASSES_ROOT.

With that in mind here is an updated function. Please let me know if you have any thoughts.

    Public Shared Function IsInstalled() As Boolean
        Static BarTenderProgID As String = "BarTender.Application"

        'Check if COM class exists on PC
        If Type.GetTypeFromProgID(BarTenderProgID) Is Nothing Then Return False

        'When Bartender is uninstalled, it leaves behind the above ProgID, so need to dig a bit deeper:

        'Search HKEY_CLASSES_ROOT for ProgID
        Dim comKey As RegistryKey = Registry.ClassesRoot.OpenSubKey(BarTenderProgID & "\\CLSID")
        If comKey Is Nothing Then Return False

        'Get default value i.e. the CLSID
        Dim clsID As String = comKey.GetValue("")
        If String.IsNullOrEmpty(clsID) Then Return False

        'Search HKEY_CLASSES_ROOT for CLSID\{...}\LocalServer32
        comKey = Registry.ClassesRoot.OpenSubKey("CLSID\\" & clsID & "\\LocalServer32")
        If comKey Is Nothing Then Return False

        'Get default value i.e. the EXE that contains the COM class (e.g. "C:\Program Files\Seagull\BarTender 2021\BarTend.exe")
        Dim Path As String = comKey.GetValue("")
        If String.IsNullOrEmpty(Path) Then Return False

        'Path has double-quotes around it which need removing
        Path = Path.Trim(""""c)
        If String.IsNullOrEmpty(Path) Then Return False

        'Does LocalServer32 path still exist?
        Return IO.File.Exists(Path)
    End Function

Please sign in to leave a comment.