/build/static/layout/Breadcrumb_cap_w.png

Problem with Reading registry through SCCM 2012

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

Answers (5)

Posted by: anonymous_9363 8 years ago
Red Belt
0
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).

Comments:
  • It is working with PSEXEC but not with SCCM. - ur00361883 8 years ago
Posted by: ur00361883 8 years ago
Black Belt
0
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)

Posted by: anonymous_9363 8 years ago
Red Belt
0
Good point. Or the OP could simply call the 64-bit flavour of CScript/WScript which is a tad simpler.

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

    May be a layman question. - ur00361883 8 years ago
Posted by: anonymous_9363 8 years ago
Red Belt
0
Google "sysnative"

Comments:
  • But I am browsing directly the vbscript files, not passing as parameter to cscript/wscript - ur00361883 8 years ago
    • 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:
      http://myitforum.com/myitforumwp/2012/06/26/configmgr-2012-console-automated-deployment-walkthrough/6-26-2012-2-12-11-pm/

      This doesn't apply for the 'Package' model so when you are using SCCM packages you should consider mentioned above 'sysnative' command. - rad33k 8 years ago
Posted by: anonymous_9363 8 years ago
Red Belt
0
Errrr...not when SCCM runs it, you're not!

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:

Share

 
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