1

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

amaturcoder
  • 25
  • 1
  • 7
  • Can't even remember when I last wrote a script, but have you checked if sValue is Null? Does the Path exists? – David Sdot Sep 26 '13 at 09:22
  • @DavidSdot, Did check and sValue is null. I think the path is fine because i am getting the major revision of the version when assign the result to vers(mentioned in the last part of the question). – amaturcoder Sep 26 '13 at 09:30
  • ok, and have you tried GetExpandedStringValue? or other way round what is the type of DLLVersion – David Sdot Sep 26 '13 at 09:35
  • AND the value you get in the vers var is actually the error code GetStringValue returns! – David Sdot Sep 26 '13 at 09:45
  • Have not tried GetExpandedStringValue. Will look into it. DLLVersion is just a string value that i have given to the variable strValueName. Frankly, do not understand how it is used. – amaturcoder Sep 26 '13 at 09:46
  • It is the same file that i have registered earlier in the code using InProcServer32. Since CodeBase worked for that, i tried CodeBase here too. but did not work – amaturcoder Sep 26 '13 at 09:49
  • Use regedit to check of what type DLLVersion is, String is Reg_SZ - Expanded is Reg_Expand_rz – David Sdot Sep 26 '13 at 09:57
  • Tried GetExpandedStringValue. Still dosent work. if what you are saying is true and it is infact the error code, how do i make sure the address is correct. And i have used the same CLSID as earlier in the code to access the same class. only then it was not registered and now it is registered. that shouldn't change the CLSID – amaturcoder Sep 26 '13 at 09:58
  • You'll have to check if svalue is Null then it does not exsist, if it's empty then it is not set but exsist. For now I would recommend regedit to check if the CLSID and type of DLLVersion are correct. – David Sdot Sep 26 '13 at 10:20
  • Ya, using regedit helped a lot. The CLSID was correct but was using the the wrong value for strValueName.Thanks – amaturcoder Sep 26 '13 at 10:50

1 Answers1

1

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).

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328