跳至主內容

搜尋

搜尋

Need some way to test if Bartender is installed

評論

1 條評論

  • Avatar
    Ian Dyer

    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

    0

登入寫評論。