0

我正在尝试查看用户计算机上安装了哪个版本的 Navisworks。我已使用此线程中的示例并使用 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

结束功能

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

结束子

代码运行到函数中的 ReadRegistry 抛出错误 Invalid use of a Null

任何帮助表示赞赏

4

0 回答 0