Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 7

<job id="RegionalSettings"> <script language="VBScript" src="ZTIUtility.

vbs"/> <script language="VBScript"> '############################################################################### ########## '# MICROSOFT LEGAL STATEMENT FOR SAMPLE SCRIPTS/CODE '############################################################################### ########## '# This Sample Code is provided for the purpose of illustration only and is no t '# intended to be used in a production environment. '# '# THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT W ARRANTY '# OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED '# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. '# '# We grant You a nonexclusive, royalty-free right to use and modify the Sampl e Code '# and to reproduce and distribute the object code form of the Sample Code, pr ovided '# that You agree: '# (i) to not use Our name, logo, or trademarks to market Your software p roduct '# in which the Sample Code is embedded; '# (ii) to include a valid copyright notice on Your software product in wh ich '# the Sample Code is embedded; and '# (iii) to indemnify, hold harmless, and defend Us and Our suppliers from and '# against any claims or lawsuits, including attorneys fees, that aris e '# or result from the use or distribution of the Sample Code. '############################################################################### ########## ' //*************************************************************************** ' // ***** Script Header ***** ' // ' // Solution: Solution Accelerator - Microsoft Deployment Toolkit ' // File: RegionalSettings.wsf ' // ' // Purpose: Script to set Regional and Language Settings after the OS ' // is installed. ' // ' // Refrences: XP - http://support.microsoft.com/?id=289125 ' // Vista - http://blogs.msdn.com/michkap/archive/2006/05/30/610505. aspx ' // - http://www.microsoft.com/globaldev/vista/vista_tools/vis ta_command_line_international_configuration.mspx ' // - http://msdn.microsoft.com/en-ie/goglobal/bb964650(en-us) .aspx ' // ' // Usage: cscript.exe RegionalSettings.wsf ' // ' // This script uses the MDT Properties UserLocale, SystemLocale, ' // InputLocale (XP), KeyboardLocale (Vista and higher), UILanguage ' // and the custom property GeoID to create the settings file. ' // (Note that SystemLocale is only a standard property

' // in MDT 2010 and later. SystemLocale must be added as a ' // custom property for versions of MDT before 2010. If ' // SystemLocale is not specified, then the value of UserLocale ' // is used instead.) ' // These properties can also be passed as command line parameters ' // when using the script standalone - outside of a task sequence. ' // ' // Version: 1.0.3 ' // ' // History: ' // 1.0.0 MDM 06/26/2009 Created initial script. ' // 1.0.1 MDM 01/15/2010 Fixed bugs and added SystemLocale. ' // 1.0.2 MDM 05/07/2010 Added oFile.Close for Vista settings file. ' // 1.0.3 MDM 08/18/2010 Added RunCommand, GetWmiPropertyValue, and WMIDateS tringToDate ' // functions. Replaced using oEnvironment.Item("OsCur rentBuild") ' // with GetWmiPropertyValue("root\cimv2", "Win32_Opera tingSystem", "BuildNumber"). ' // Now using RunCommand to run intl.cpl command. ' // ' // ***** End Header ***** ' //*************************************************************************** '//---------------------------------------------------------------------------'// '// Global constant and variable declarations '// '//---------------------------------------------------------------------------'Option Explicit Dim iRetVal '//---------------------------------------------------------------------------'// End declarations '//---------------------------------------------------------------------------Const TRISTATE_USE_DEFAULT Const TRISTATE_TRUE Const TRISTATE_FALSE Const OVERWRITE_TRUE Const OVERWRITE_FALSE Const TEXT_USE_DEFAULT Const TEXT_UNICODE Const TEXT_ASCII = -2 = -1 = 0 = -1 = 0 = -2 = -1 'Open the file as Unicode. = 0 'Open the file as ASCII.

'//---------------------------------------------------------------------------'// Main routine '//---------------------------------------------------------------------------On Error Resume Next iRetVal = ZTIProcess ProcessResults iRetVal On Error Goto 0

'//--------------------------------------------------------------------------'// '// Function: ZTIProcess() '// '// Input: None '// '// Return: Success - 0 '// Failure - non-zero '// '// Purpose: Perform main ZTI processing '// '//--------------------------------------------------------------------------Function ZTIProcess() oLogging.CreateEntry "------------ Initialization " & oUtility.ScriptName & " -------------", LogTypeInfo On Error Resume Next ZTIProcess = Success sScriptFolder = oUtility.ScriptDir ' Create the file and write the standard header sTsLogPath = oEnvironment.Item("_SMSTSLogPath") If sTsLogPath = "" Then sOutputFolder = oUtility.LogPath Else sOutputFolder = sTsLogPath End If sUserLocale = "" sInputLocale = "" sKeyboardLocale = "" sUILanguage = "" ' GeoID is not an MDT standard property sGeoID = "" sUserLocale = oEnvironment.Item("UserLocale") sSystemLocale = oEnvironment.Item("SystemLocale") sInputLocale = oEnvironment.Item("InputLocale") sKeyboardLocale = oEnvironment.Item("KeyboardLocale") sUILanguage = oEnvironment.Item("UILanguage") ' GeoID is not an MDT standard property sGeoID = oEnvironment.Item("GeoID") ' Create XML output File sFile = sOutputFolder & "\RegionalOptions.log" oLogging.CreateEntry "Creating output Regional Settings file " & sFile, LogT ypeInfo Set oFile = oFSO.CreateTextFile(sFile, OVERWRITE_TRUE) If GetWmiPropertyValue("root\cimv2", "Win32_OperatingSystem", "BuildNumber") >= 6000 Then

'**** Vista Settings oLogging.CreateEntry "Creating Regional Settings XML file for Vista and higher", LogTypeInfo oFile.WriteLine "<gs:GlobalizationServices xmlns:gs=""urn:longhornGlobal izationUnattend"">" oFile.WriteLine "" oFile.WriteLine " <!-- user list -->" oFile.WriteLine " <gs:UserList>" oFile.WriteLine " <gs:User UserID=""Current"" CopySettingsToDefau ltUserAcct=""true"" CopySettingsToSystemAcct=""true""/>" oFile.WriteLine " </gs:UserList>" oFile.WriteLine "" If sGeoID <> "" Then oFile.WriteLine " oFile.WriteLine " oFile.WriteLine " 34) & "/>" oFile.WriteLine " oFile.WriteLine "" End If <!-- GeoID -->" <gs:LocationPreferences>" <gs:GeoID Value=" & chr(34) & sGeoID & chr( </gs:LocationPreferences>"

If sUILanguage <> "" Then oFile.WriteLine " <!-- UI Language Prefernces -->" oFile.WriteLine " <gs:MUILanguagePreferences>" oFile.WriteLine " <gs:MUILanguage Value=" & chr(34) & sUILang uage & chr(34) & "/>" oFile.WriteLine " </gs:MUILanguagePreferences>" oFile.WriteLine "" End If If sSystemLocale <> "" Then oFile.WriteLine " <!-- system locale -->" oFile.WriteLine " <gs:SystemLocale Name=" & chr(34) & sSystemLoca le & chr(34) & "/>" oFile.WriteLine "" ElseIf sUserLocale <> "" Then oFile.WriteLine " <!-- system locale -->" oFile.WriteLine " <gs:SystemLocale Name=" & chr(34) & sUserLocale & chr(34) & "/>" oFile.WriteLine "" End If If sKeyboardLocale <> "" Then oFile.WriteLine " <!-- input preferences -->" oFile.WriteLine " <gs:InputPreferences>" arrInputLocales = Split(sKeyboardLocale , ";") strLocaleLines = "" If IsArray(arrInputLocales) Then For i = 0 to UBound(arrInputLocales) If i = 0 Then oFile.WriteLine " <gs:InputLanguageID Action=" & chr(34) & "add" & chr(34) & " ID=" & chr(34) & arrInputLocales(i) & chr(34) & " Default=" & chr(34) & "true" & chr(34) & "/>" Else oFile.WriteLine " <gs:InputLanguageID Action=" & chr(34) & "add" & chr(34) & " ID=" & chr(34) & Trim(arrInputLocales(i)) & chr(34

) & "/>" End If Next Else oFile.WriteLine " <gs:InputLanguageID Action=" & chr(34) & "add" & chr(34) & " ID=" & chr(34) & sKeyboardLocale & chr(34) & " Default=" & chr(34) & "true" & chr(34) & "/>" End If oFile.WriteLine " oFile.WriteLine "" End If </gs:InputPreferences>"

If sUserLocale <> "" Then oFile.WriteLine " <!-- user locale -->" oFile.WriteLine " <gs:UserLocale>" oFile.WriteLine " <gs:Locale Name=" & chr(34) & sUserLocale & chr(34) & " SetAsCurrent=""true"" ResetAllSettings=""true""/>" oFile.WriteLine " </gs:UserLocale>" oFile.WriteLine "" End If oFile.WriteLine "</gs:GlobalizationServices>" oFile.WriteLine "" oFile.Close sCmd = "cmd /c control.exe intl.cpl,,/f:" & chr(34) & sFile & Chr(34) oLogging.CreateEntry "About to run command: " & sCmd, LogTypeInfo RunCommand sCmd Else '**** XP Settings oLogging.CreateEntry "Creating Regional Settings INI file for XP", LogTy peInfo oFile.WriteLine "[RegionalSettings]" oFile.WriteLine "LanguageGroup = 1,7,11" If sUserLocale <> "" Then oFile.WriteLine "UserLocale = " & sUserLocale oFile.WriteLine "UserLocale_DefaultUser = " & sUserLocale End If If sSystemLocale <> "" Then oFile.WriteLine "SystemLocale = " & sSystemLocale ElseIf sUserLocale <> "" Then oFile.WriteLine "SystemLocale = " & sUserLocale End If If sInputLocale <> "" Then oFile.WriteLine "InputLocale = " & sInputLocale oFile.WriteLine "InputLocale_DefaultUser = " & sInputLocale End If If sUILanguage <> "" Then oFile.WriteLine "MUILanguage = " & sUILanguage oFile.WriteLine "MUILanguage_DefaultUser = " & sUILanguage

End If oFile.WriteLine "" oFile.Close sCmd = "cmd /c rundll32.exe shell32,Control_RunDLL intl.cpl,,/f:" & chr( 34) & sFile & Chr(34) oLogging.CreateEntry "About to run command: " & sCmd, LogTypeInfo RunCommand sCmd End If oLogging.CreateEntry "------------ Departing " & oUtility.ScriptName & " ------------", LogTypeInfo End Function Function GetWmiPropertyValue(strNameSpace, strClassName, strPropertyName) On Error Resume Next strPropertyValue = "" set oWmiClass = getobject("winmgmts:" & strNameSpace).get(strClassName,&h200 00) 'amended set oWmiProperties = oWmiClass.Properties_ Set objWMIService = GetObject("winmgmts:\\" & "." & "\" & strNameSpace) Set colItems = objWMIService.ExecQuery("Select * from " & strClassName,,48) For Each objItem in colItems For Each objProperty in oWmiProperties sLine = "" 'WScript.Echo "- " & objProperty.name & ": " & strPropertyName If objProperty.Name = strPropertyName Then If objProperty.IsArray = True Then sLine = "str" & objProperty.Name & " = Join(objItem." & objP roperty.Name & ", " & Chr(34) & "," & Chr(34) & ")" & vbCrLf sLine = sLine & "strPropertyValue = str" & objProperty.Name ElseIf objProperty.CIMTYPE = 101 Then bHasDates = True sLine = "strPropertyValue = WMIDateStringToDate(objItem." & objProperty.Name & ")" Else sLine = "strPropertyValue = objItem." & objProperty.Name End If 'WScript.Echo sLine Execute sLine End If Next Next GetWmiPropertyValue = strPropertyValue End Function

Function WMIDateStringToDate(dtmDate) 'WScript.Echo dtm: WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _ Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _ & " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmD ate,13, 2)) End Function Function RunCommand(sCmd) oLogging.CreateEntry "RunCommand function: About to run command: " & sCmd, L ogTypeInfo On Error Resume Next Err.Clear iRetVal = oShell.Run(sCmd, 0, true) If Err then oLogging.CreateEntry "RunCommand function: Cmd & """: " & Err.Description & " (" & Err.Number RunCommand = Err.Number EXIT FUNCTION ElseIf iRetVal <> Success then oLogging.CreateEntry "RunCommand function: Cmd & """, rc = " & iRetVal, LogTypeError RunCommand = iRetVal EXIT FUNCTION Else oLogging.CreateEntry "RunCommand function: sCmd, LogTypeInfo RunCommand = Success End if On Error Goto 0 End Function </script> </job>

ERROR running command """ & s & ")", LogTypeError

ERROR running command """ & s

Successfully ran command: " &

You might also like