Friday, May 23, 2014

Checking 64bit Registry-Display Version value using VB Scripts

On error Resume Next
Value = "3.0.85.0"
strComputer = "."
Const HKLM = &h80000002
Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
objCtx.Add "__ProviderArchitecture", 64
objCtx.Add "__RequiredArchitecture", TRUE
Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
Set objServices = objLocator.ConnectServer("","root\default","","",,,,objCtx)
Set objStdRegProv = objServices.Get("StdRegProv")

Set Inparams = objStdRegProv.Methods_("GetStringValue").InParameters
'Inparams.Hdefkey = HKLM
Inparams.Ssubkeyname = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{100E94A6-F85A-E828-9EE3-C1DD14706B6A}"
Inparams.SValueName = "DisplayVersion"
Set Outparams = objStdRegProv.ExecMethod_("GetStringValue", Inparams,,objCtx)

strValue = Outparams.sValue

If strvalue=value then
MSGBOX "success"

Else
MSGBOX "NOT success"  
End If


2 comments:

  1. How do you get the actual registry value to display in a MsgBox rather than using wscript.echo?

    ReplyDelete
    Replies
    1. Was running within an HTA, changed my calling .vbs for the application to use: strArgs = "cmd /c %windir%\System32\mshta.exe C:\...hta" rather than the default mshta.exe which is 32-bit. This was causing the value to change to NULL when switching from the 64bit Wscript to the MsgBox ran from 32bit mshta. Was able to use regular registry commands that worked with WOW6432 entries to pull Software\Microsoft values.

      Delete