VBScript – Batch – SCCM – Loading User’s Registry Hive

email me

This is a code snippet for loading each user’s profile on a workstation. Note, objSubKey is the returned user SID and strUser is the returned username. This can be extremely useful if you have computers with multiple user profiles that need modifications made to their registry hives…in a scripted, enterprise deployment.

VBScript

'LOAD REGISTRY HIVE - THIS IS UNTESTED
objShell.Run "%comspec% /c REG.exe LOAD HKU\" & objSubkey & " " & "C:\Users\" & strUser & "\NTUSER.DAT",0,true

'ADD YOUR KEYS HERE
objShell.Run "%comspec% /c REG.exe DELETE " & chr(34) & "HKEY_USERS\" & objSubkey & "\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges\Range1" & chr(34) & " /f",0,true

objShell.Run "%comspec% /c REG.exe DELETE " & chr(34) & "HKEY_USERS\" & objSubkey & "\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Ranges" & chr(34) & " /f",0,true

'TIMING
WScript.Sleep 2000

'UNLOAD HIVE KEY
objShell.Run "%comspec% /c REG.exe UNLOAD HKU\" & objSubkey,0,true

 

This is how you would do something similar, but inside an SCCM Task Sequence. I load the Default user profile, add some reg keys, and then unload the profile.

Each command will be in a Run Command Line item.

Batch Commands for SCCM Task Sequence

cmd /c REG LOAD HKLM\DEFAULT c:\users\default\ntuser.dat

cmd /c REG ADD “HKLM\DEFAULT\SOFTWARE\Policies\Microsoft\Office\16.0\Common\General” /v “OptInDisable” /t REG_DWORD /d 1 /f /REG:64

cmd /c REG ADD “HKLM\DEFAULT\SOFTWARE\Policies\Microsoft\Office\16.0\Registration” /v “AcceptAllEulas” /t REG_DWORD /d 1 /f /REG:64

cmd /c REG ADD “HKLM\DEFAULT\Software\Citrix\Receiver” /v “HideAddAccountOnRestart” /t REG_DWORD /d 1 /f /REG:64

cmd /c REG ADD “HKLM\DEFAULT\Software\Microsoft\Windows NT\CurrentVersion\Windows” /v “LegacyDefaultPrinterMode” /t REG_DWORD /d 1 /f /REG:64

cmd /c REG UNLOAD HKLM\DEFAULT