Create regvalues from TS variables

script to add in a TS to save certain task sequence variables to the registry, for whatever reason ...
Syntas looks like this. First argument is the start name of the variables. Second argument is the registry key to store the variables:
cscript CreateRegvaluesFromTSVariables.vbs "PostTS" "Software\HM\PostTSInstall"

Const HKEY_LOCAL_MACHINE = &H80000002

Set oRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
Set oArguments = WScript.Arguments

If oArguments.Count <> 2 Then
	WScript.Echo "Usage:"
	WScript.Echo "cscript " & Wscript.ScriptName & " ""variableName"" ""RegKey"""
	WScript.Echo " variableName" & vbTab & "Ex: ""HM"" if TS variables are Called HMIPNetmask and HMIPServer"
	WScript.Echo " RegKey" & vbTab & "Ex: Software\HM\ (Always under HKLM)"
	WScript.Echo ""
	WScript.Echo "The name after variableName will be created in the registry under RegKey with the value specified for the variable."
	WScript.Echo "Ex: If Task Sequence Variable HMIPNetmask is set to"
	WScript.Echo """IPNetMask"" will be created as a string under RegKey with Value """""
	WScript.Quit 10022 'An invalid argument was supplied.
End If

sVariable = oArguments.Item(0)
sRegKey = oArguments.Item(1)


'Gather OSD Variables and create registry values
Set osdVar = CreateObject("Microsoft.SMS.TSEnvironment")  
For Each sVar in osdVar.GetVariables() 
	If LCase(Left(sVar, Len(sVariable))) = LCase(sVariable) Then
		sValueName = Replace(sVar, sVariable, "", 1, 1, vbTextCompare)
		sValue = osdVar(sVar)
		If sValue <> "" Then
			CreateStringValue sRegKey, sValueName, sValue
		End if
	End If

Sub CreateKey(sRegKey)
	oRegistry.CreateKey HKEY_LOCAL_MACHINE, sRegKey
End Sub

Sub CreateStringValue(sRegKey, sValueName, sValue)
	oRegistry.SetStringValue HKEY_LOCAL_MACHINE, sRegKey, sValueName, sValue
End Sub
Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

No trackbacks yet.