Domanda

I have a code in VB to find the version of a COM dll that i have installed. the relevant code is:

Const HKEY_LOCAL_MACHINE = &H80000002
---------
---------
Set objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")

strKeyPath = "SOFTWARE\Classes\Wow6432Node\CLSID\{394B1F33-115C-33E5-A008-36E32C5340D9}\InprocServer32"
strValueName = "CodeBase"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
---------
---------
strKeyPath = "SOFTWARE\Classes\Wow6432Node\CLSID\{394B1F33-115C-33E5-A008-36E32C5340D9}\Version"
strValueName = "DLLVersion"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,sValue
Wscript.Echo sValue
---------

When i run the code is get the error: Directory\file.vbs(37,1) Microsoft VBScript runtime error: Type mismatch

The 37th line the last one in the code above:

Wscript.Echo sValue

The first GetStringValue is working fine( where i have used InProcServer32) Searched a lot but do not know how to resolve this.

Also i tried using different names strValueName. i tried "CodeBase". i also tried using an empty string to get the default value.

I also tried to get the value of the function in a variable as follows:

set vers=objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,sValue

vres gets the value of only the main revision in the version. for example if version is 2.4.7.0 then vers has value 2

È stato utile?

Soluzione

You're misunderstanding how GetStringValue works. The data read from the registry value is returned via the out parameter sValue:

retval = reg.GetStringValue(HKEY_LOCAL_MACHINE, strKeyPath, strValueName, sValue)

If no data can be read that value is set to Null.

The return value of the method:

retval = reg.GetStringValue(HKEY_LOCAL_MACHINE, strKeyPath, strValueName, sValue)

is an integer indicating whether the method call succeeded or not. A return value of 0 means that the call was successful. a non-zero value means that something went wrong. A value of 2 in particular indicates that the registry key you're trying to read from doesn't exist.

Also, you must not use the Set keyword here. That keyword must only be used when assigning objects to variables. In this case, however, the return value is a primitive data type (integer).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top