Task Sequence Time Zone Fun

I recently had a situation where we were looking for a way to set time zones on Windows 7 clients during Operating System Deployment.  While there are certainly many different ways to accomplish this, our case was a little different.  We were deploying to unknown machines that could be in any number of time zones, so, using a Task Sequence variable wouldn’t have been as dynamic as we wanted. The Domain Controllers, OU’s, collections, etc… weren’t always in the same time zone, either, so, we couldn’t base our solution on any of these.  We decided that, in this scenario, the best way to determine the time zone would be to base it on whatever DHCP server the client was using, as that was the only unique service we definitely knew each location had.  So, here is an example of  how we can use a VB script that will pull the time zone data from the client’s DHCP server and set it locally.  We can place this script in a Task Sequence and run it using an account that has rights to read the SYSTEM\CurrentControlSet\Control\TimeZoneInformation key on the DHCP servers.  Of course, this is just an example, you should always work out logic and test before implementing any solution.  🙂


' ***set local machine variable
strComputer = "."

' ***Find DHCP Server
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\Cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where Not DHCPServer Like '255%'")
For Each objItem in colItems
If objItem.DHCPEnabled = True Then

' ***Get Registry Key Value From DHCP Server
const HKEY_LOCAL_MACHINE = &H80000002
Set StdOut = WScript.StdOut
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
objItem.DHCPServer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Control\TimeZoneInformation"
strValueName = "TimeZoneKeyName"
oReg.GetExpandedStringValue HKEY_LOCAL_MACHINE,strKeyPath,_

' ***Set Time Zone on Local Machine
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "c:\windows\system32\tzutil.exe /s " & """" & strValue & """"

' ***It's a Trap!
MsgBox "DHCP Is Not Enabled - A Static IP Configured"
End If


Comments (0)

Skip to main content