Access VBA WMI methods for Win32_products

Jerry Barrett 21 Reputation points
2021-07-19T09:15:31.013+00:00

Hi Folks

Using Windows 10 Pro V2009 64 Bit, with Access 2019 32Bit. An Access App printing labels through Bartender from SAP.

I have adapted this code to give me a list of installed programs on a pc. I was using the WMI win32_Products method which seemed to find everything I was after but was really slow and I read its not best practice these days.

So I changed to the uninstall registry list method but discovered not all programs are listed in the uninstall registry and there may be other locations to search?

I have tried both the registry's listed registry locations for the 32bit and 64bit registries but the product I want it to find although listed in the uninstall registry(manual search is good) its missing from my table at the end.

This: "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" and
this: "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" in the HKLM section.

Public Function GetAddRemove(sComp)
'Function credit to Torgeir Bakken
Dim cnt, oReg, sBaseKey, iRC, aSubKeys
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & _
sComp & "/root/default:StdRegProv")
sBaseKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
iRC = oReg.EnumKey(HKLM, sBaseKey, aSubKeys)

Dim sKey, sValue, sTmp, sVersion, sDateValue, sYr, sMth, sDay

For Each sKey In aSubKeys
iRC = oReg.GetStringValue(HKLM, sBaseKey & sKey, "DisplayName", sValue)

If iRC <> 0 Then
oReg.GetStringValue HKLM, sBaseKey & sKey, "QuietDisplayName", sValue
End If
If sValue <> "" Then
dispname = sValue

iRC = oReg.GetStringValue(HKLM, sBaseKey & sKey, "InstallLocation", sValue)
instloc = sValue

SQLstr = "INSERT INTO TblInstalledApps (installed, ExecLoc) VALUES ('" & dispname & "','" & instloc & "');"
DoCmd.RunSQL SQLstr

End If
Next

End Function

This works 100s of times faster than the win32_Products WMI search so I don't want to go back, but I need it to list at least the app I want to search for on a pc if its installed 'Bartender' but it's missing from the data retrieved from the Uninstall Registry.

Is there another method of retrieving a list of installed products from Windows in VBA into an Access table or have I got something wrong in the code?

Many Thanks

Jerry

Developer technologies Visual Basic for Applications
0 comments No comments
{count} votes

Accepted answer
  1. Tom van Stiphout 1,861 Reputation points MVP
    2021-07-20T13:03:55.223+00:00

    I wonder if that would show up on a PC with just Access Run Time installed

    Tools > References is a list of all ActiveX objects installed on the machine.

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Tom van Stiphout 1,861 Reputation points MVP
    2021-07-20T03:15:23.133+00:00

    Does Bartender show up in Access code window > Tools > References?
    If yes, then you should be able to create an object of that type similar to:
    dim o as object
    set o = createobject("Excel.Application")
    if o is nothing then
    msgbox "Yo!. Excel is not installed", vbExclamation

    0 comments No comments

  2. Jerry Barrett 21 Reputation points
    2021-07-20T08:47:33.257+00:00

    Hi Many Thanks for your reply.

    Yes Bartender is in the Tools -> References section of Access. Nice :)

    However, I wonder if that would show up on a PC with just Access Run Time installed, not the development version of Access?

    There are two barcode printing products we use Bartender and Lighthouse CJ Pro. Unfortunately CJ Pro doesn't show up in the Tools References options, so I'll have to stick to the current method to confirm if that is installed and your idea for a Bartender install :)

    Regards
    Jerry

    0 comments No comments

  3. Jerry Barrett 21 Reputation points
    2021-07-27T07:52:07.497+00:00

    Hi yes it appears to find the bartender product as you predicted :) Thank you

    So your solution and a targeted win32_products search speeded up the process a lot, so much I don't need a splash 'please wait' screen. very cool

    Appreciate your help
    Jerry

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.