VBA to check version of software installed HKEY_LOCAL_MACHINE

365 views Asked by At

I'm trying to check to see which version of Navisworks installed on a users machine. I have used the example from this thread and modified Find registry key using Excel VBA

Function ReadRegistry(RootKey, Key As String, Value As String, Optional RegType As Integer = 32) As String

Dim oCtx, oLocator, oReg, oInParams, oOutParams

Set oCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
oCtx.Add "__ProviderArchitecture", RegType

Set oLocator = CreateObject("Wbemscripting.SWbemLocator")
Set oReg = oLocator.ConnectServer("", "root\default", "", "", , , , oCtx).Get("StdRegProv")

Set oInParams = oReg.Methods_("GetStringValue").InParameters
oInParams.hDefKey = RootKey
oInParams.sSubKeyName = Key
oInParams.sValueName = Value

Set oOutParams = oReg.ExecMethod_("GetStringValue", oInParams, , oCtx)

ReadRegistry = oOutParams.sValue

End Function

Sub NavisworksVersion()
Const HKEY_LOCAL_MACHINE = &H80000002
MsgBox ReadRegistry(HKEY_LOCAL_MACHINE, "Software\Autodesk\Navisworks API Runtime\18\Navisworks Manage", "Path")

End Sub

The code runs upto the ReadRegistry in the Function where is throws an error Invalid use of a Null

Any help is appreciated

0

There are 0 answers