The below script is reading the registry value and storing to a variable strValue.
It is working fine if we execute directly or as a parameter to cscript or vbscript.But it is not storing any value when we execute this through SCCM as an installer program.
Const HKEY_LOCAL_MACHINE = &H80000002
Dim fn_objReg    : Set fn_objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
Dim strKeyPath   : strKeyPath    = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
strValueName = "DisplayVersion"
  Dim strProductCode : strProductCode = "{88509E20-3936-4D88-A1C0-B274C7BB5151}"
strKeyPath = strKeyPath & strProductCode
  fn_objReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,strValue
0 Comments   [ + ] Show Comments


Please log in to comment


I suspect this is to do with the 'impersonationLevel'. Google the different values for that and experiment using PSExec (saves having to wait for SCCM to get its act together).
Answered 03/23/2016 by: VBScab
Red Belt

  • It is working with PSEXEC but not with SCCM.
Please log in to comment
The root cause for the above problem is SCCM is trying to access 32 bit version of WScript/CScript.So it isn't able to see the 64 bit registry hive.

The below custom function solved this problem.
Function ReadRegStr (RootKey, Key, Value, RegType)
    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)

    ReadRegStr = oOutParams.sValue
End Function

To use this :
strValue = ReadRegStr (HKEY_LOCAL_MACHINE, strKeyPath,strValueName, 64)

Answered 03/27/2016 by: ur00361883
Green Belt

Please log in to comment
Good point. Or the OP could simply call the 64-bit flavour of CScript/WScript which is a tad simpler.
Answered 03/29/2016 by: VBScab
Red Belt

  • Can we do any change in the settings of sccm 2012, to use 64 bit version of CScript/WScript.

    May be a layman question.
Please log in to comment
Google "sysnative"
Answered 03/29/2016 by: VBScab
Red Belt

  • But I am browsing directly the vbscript files, not passing as parameter to cscript/wscript
    • As far as I know, when you are creating new Application in SCCM it starts as 64bit process by default. You can set an option to 'start as 32 bit process on 64bit OS' as you can see at the bottom of this image:

      This doesn't apply for the 'Package' model so when you are using SCCM packages you should consider mentioned above 'sysnative' command.
Please log in to comment
Errrr...not when SCCM runs it, you're not!
Answered 03/29/2016 by: VBScab
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity
Admin Script Editor
Admin Script Editor is an integrated scripting environment available free here at ITNinja