Scripting Question

Problem with Reading registry through SCCM 2012

03/23/2016 3024 views
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


All Answers

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: anonymous_9363
Red Belt

  • It is working with PSEXEC but not with SCCM.
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
Black Belt

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: anonymous_9363
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.
Google "sysnative"
Answered 03/29/2016 by: anonymous_9363
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.
Errrr...not when SCCM runs it, you're not!
Answered 03/29/2016 by: anonymous_9363
Red Belt

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:


This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ