locked
TRouble running a portion of VBscript during SCCM OSD RRS feed

  • Question

  • Hi,

    In my SCCM 2012 R2 OSD TS, I am using a post script vbs file. This post script does some customizations like setting some registry value, coying bunch of files, cleanup etc. It is legacy stuff but works well for the windows 7 deployment using SCCM TS.

    I am trying to include below lines of code into my original script to achieve following:

    1> Setting some HKCU registry to set a Particular theme. The abc.theme gets copied to c:\Windows\Resources\Themes\ Folder during OSD and once these registry values are set the theme seems to install.

    2> Setting desktop background. I am using a custom setbkgnd.exe to set up the abc.bmp as desktop background. abc.bmp  gets copied to c:\windows\abc folder during OSD.

    Now my post build script works perfectly without this portion of script. Also if I disable the post build task in my TS and manually execute the post build script with this code included, that also work. Or if I execute post my post build script during OSD without these line of code and later execute only these codes manually using vbscript, that also work. However if I create a separate package using this vbscript and include is as a step in my Task sequence or push it through Software centre, it fails. Leaving me to think that these lines of codes are not compatible with SCCM deployment and I dont understand why.

    Probably what I am trying to achieved could be done through multiple different ways(suggestions welcome), I would still like to see these lines work in my post script vbs. Below is what the portion of vbscript, (which I am calling as Sub in my post script) which is problematic.

    Dim objshell

    Set objShell = createObject("Wscript.shell")

    Const HKEY_CURRENT_USER = &H80000001

    strComputer = "."

    Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _

    strComputer & "\root\default:StdRegProv")

    strKeyPath = "Software\Policies\Microsoft\Windows\Personalization"

    StrKeyPath2 = "Software\Microsoft\Windows\CurrentVersion\Themes"

    oReg.CreateKey HKEY_CURRENT_USER,strKeyPath

    strValueName = "ThemeFile"

    StrValueName2 = "CurrentTheme"

    'Enabled

    strValue = "C:\Windows\Resources\Themes\ABC.theme"

    oReg.SetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue

    OReg.SetStringValue HKEY_CURRENT_USER,strkeypath2,strvalueName2,strvalue

    objShell.Run "C:\Windows\SetBkgnd.exe C:\Windows\ABC\ABC.bmp"

    'Not Configured

    'oReg.DeleteValue HKEY_CURRENT_USER,strKeyPath,strValueName


    Tuesday, May 1, 2018 4:46 PM

Answers

  • Hello

    you are trying to apply settings to the Current User section of the registry which won't work during a task sequence as the task sequence runs for Computers not users.you can get around this by mounting the registry hive for the Default User and making the changes using your chosen registry file which is pointing to this mount point, then commit the changes.

    Below is an example for modifying HKCU settings

    The first step will Load the Default User registry hive into a mountpoint called Defuser using a Run Command Line step like so

    cmd.exe /c reg.exe load HKEY_LOCAL_MACHINE\defuser c:\users\default\ntuser.dat
     
    in the next step import the Registry file in another Run Command Line step this Registry file can be a file in a package.

    cmd.exe /c reg.exe import "Userprefs.reg"

    and finally commit the changes in another Run Command Line step

    cmd.exe /c reg.exe unload HKEY_LOCAL_MACHINE\defuser
     
    and that's all using this methodology you can set any HKCU keys you want to be applied during an OSD task sequence


    Regards, Regin Ravi

    • Marked as answer by Alcox Tuesday, June 26, 2018 4:58 PM
    Tuesday, May 1, 2018 6:01 PM

All replies

  • SCCM executes these steps under the system account, so if you were to modify the registry you would need to load the default user registry hive, make changes, then unload the hive. 

    I would advise against doing this and just use GPO's for the customisations you have pointed out, these are all easily achieved with some simple Group Policies. 


    Dan Padgett | Blog: http://execmgr.net | Twitter: @danjpadgett


    Tuesday, May 1, 2018 4:51 PM
  • Thanks for responding promptly. Yes I agree GPO would be the best place to make these changes. However my client wants to include these settings in the post script due to some legacy stuffs.
    Tuesday, May 1, 2018 5:37 PM
  • Hello

    you are trying to apply settings to the Current User section of the registry which won't work during a task sequence as the task sequence runs for Computers not users.you can get around this by mounting the registry hive for the Default User and making the changes using your chosen registry file which is pointing to this mount point, then commit the changes.

    Below is an example for modifying HKCU settings

    The first step will Load the Default User registry hive into a mountpoint called Defuser using a Run Command Line step like so

    cmd.exe /c reg.exe load HKEY_LOCAL_MACHINE\defuser c:\users\default\ntuser.dat
     
    in the next step import the Registry file in another Run Command Line step this Registry file can be a file in a package.

    cmd.exe /c reg.exe import "Userprefs.reg"

    and finally commit the changes in another Run Command Line step

    cmd.exe /c reg.exe unload HKEY_LOCAL_MACHINE\defuser
     
    and that's all using this methodology you can set any HKCU keys you want to be applied during an OSD task sequence


    Regards, Regin Ravi

    • Marked as answer by Alcox Tuesday, June 26, 2018 4:58 PM
    Tuesday, May 1, 2018 6:01 PM
  • However my client wants to include these settings in the post script due to some legacy stuffs.

    What does this mean? What difference does it make ?

    >you can get around this by mounting the registry hive for the Default User and making the changes using your chosen registry file which is pointing to this mount point, then commit the changes.

    You can, by why mess with the registry hive if you don't have to? 


    Dan Padgett | Blog: http://execmgr.net | Twitter: @danjpadgett

    Tuesday, May 1, 2018 6:49 PM
  • Thanks ReginRavi for the elaborate steps. I will try those and see how it goes.
    Tuesday, May 1, 2018 7:05 PM
  • Agree reg hacking is not the best solution. Any thought on LGPO? Does that work well with SCCM 2012 R2?
    Tuesday, May 1, 2018 7:07 PM
  • Whats wrong with AD Group Policy ?

    Dan Padgett | Blog: http://execmgr.net | Twitter: @danjpadgett

    Tuesday, May 1, 2018 7:37 PM