JSI Tip 9006. How do you deal with time zone changes when your domain is on a ship, airplane, or other vehicle?

Jerold Schulman

February 2, 2005

4 Min Read
ITPro Today logo in a gray background | ITPro Today

If your domain is onboard a vehicle that travels across time zones, it is very difficult to keep the time and time zone properly set on all domain servers and members.

By default, Windows-based computers use the following hierarchy:

  • All client desktop computers and member servers nominate the authenticating domain controller as their in-bound time partner.

  • Domain controllers may nominate the primary domain controller (PDC) operations master as their in-bound time partner.

  • All PDC operations masters follow the hierarchy of domains in the selection of their in-bound time partner.

  • Following this hierarchy, the PDC operations master at the root of the forest becomes authoritative for the organization.

NOTE: See tip 8266 and links to configure the authoritative time server.

I have scripted SetTimeZone.bat to set the time zone on the authoritative time server, and GetTimeZone.bat to set the time zone, and time, on all other domain members.

NOTE: I have also scripted SetTimeZoneNumber as an alternate method of setting the time zone on the PDC emulator.

These scripts use Nltest.exe, Ntdsutil.exe, Netdom.exe, and Reg.exe, which depending on your server operating system, are either built into the O/S, or installed from the Support Tools from the operating system CD-ROM:

Windows 2000Reg.exe      Support ToolsNltest.exe   Support ToolsNetdom.exe   Support ToolsNtdsutil.exe Built-inWindows XP and Windows Server 2003Reg.exe      Built-inNltest.exe   Support ToolsNetdom.exe   Support ToolsNtdsutil.exe Built-in

NOTE: These scripts use techniques from:

Tip 7525 to set the time zone in batch.

Tip 8323 to locate all the domain controllers.

Tip 7822 to determine which domain controller holds the PDC emulator role.

Tip 0398 to validate the time zone you are setting.

NOTE: See How can I create a file of time zones, sorted from GMT -12:00 to GMT +13:00?

Setting the time zone on the PDC emulator:

The syntax for setting the time zone on the PDC emulator is:

SetTimeZone "Time Zone"

Where "Time Zone" is a valid time zone like:

"Eastern Standard Time""Atlantic Standard Time""Azores Standard Time""Cape Verde Standard Time""Central Pacific Standard Time""Dateline Standard Time""Hawaiian Standard Time""Mid-Atlantic Standard Time""Pacific Standard Time"

You do not have to use proper case as SetTimeZone.bat will adjust the case to match the operating system definition. When SetTimeZone.bat sets the time zone on the PDC emulator, it also records this time zone in a TimeZone.txt file which it copies to the NETLOGON share of every domain controller.

NOTE: If the Date and Time Properties dialog opens at the Time Zone tab, you attempted to set an invalid time zone, such as Eastern Daylight Time, when the date indicates it should be Eastern Standard Time. If this happens, immediately set the correct time zone, as the TimeZone.txt file has been improperly set.

As an alternative, you can use SetTimeZoneNumber NNN, where NNN is the time zone number from TimeZones.bat.
To set the time zone to Eastern Standard Time, use
SetTimeZoneNumber 029.

Setting the time zone, and time, on all other domain computers:

GetTimeZone.bat is started on all domain computers via a startup script.

NOTE: GetTimeZone.bat doesn't have to run on the authoritative time server, but if it is started on the PDC emulator, it will gracefully exit.

GetTimeZone.bat retrieves the time zone the the %LogonServer%NETLOGONTimeZone.txt file, sets the time zone, and even though it isn't really necessary, sets the time from the %LogonServer%. It then waits 60 seconds, which you can adjust by changing set looptime=61, before checking to see if the time zone has been changed by SetTimeZone.bat or SetTimeZoneNumber.bat.

SetTimeZone.bat contains:

@echo offif {%1}
{} @echo Syntax: SetTimeZone "Time Zone"&goto :EOFsetlocalset OK=Nset tz=%1set tz=%tz:"=%set fnd1=findstr /I "Std Dlt"set fnd2=Findstr /L /I /C:%1set fnd3=Findstr /B /I /X /L /C:%1set fnd4=Findstr /E /I /X /L /C:%1set rund=RunDLL32 shell32.dll,Control_RunDLL %SystemRoot%system32TIMEDATE.cpl,,/Zset qry=reg.exe query "HKLMSoftwareMicrosoftWindows NTCurrentVersionTime Zones"for /f "Tokens=1,2*" %%a in ('%qry% /s ^|%fnd1%^|%fnd2%') do ( for /f "Tokens=*" %%d in ('@echo %%c^|%fnd3%^|%fnd4%') do ( @echo %rund% %%d %rund% %%d set tz=%%d set OK=Y ))if "%OK%" EQU "N" @echo Invalid Time Zone:%tz%&goto finishfor /f "Tokens=1 Delims=. " %%d in ('nltest.exe /dclist:%USERDNSDOMAIN%^|Findstr /C:"Site:"') do ( @echo %tz%>\%%dNETLOGONTimeZone.txt):finishendlocal


GetTimeZone.bat contains:

@echo offsetlocalset prevtz=noneset looptime=61set server=%logonserver%set PDC=Nset ntds1=Ntdsutil.exe roles Connectionsset ntds2=Quit "select Operation Target" "List roles for connected server" Quit Quit Quitset rund=RunDLL32 shell32.dll,Control_RunDLL %SystemRoot%system32TIMEDATE.cpl,,/Zif /i "%server:~2%" NEQ "%Computername%" goto finishset netdm=netdom query /domain:%userdnsdomain%for /f "Tokens=1 Delims=. " %%c in ('nltest.exe /dclist:%USERDNSDOMAIN%^|Findstr /C:"Site:"') do ( for /f "Tokens=1" %%r in ('%ntds1% "Connect to server %%c" %ntds2%^|Findstr /L /I /B /C:"PDC"') do (  set PDC=%%c ))if "%PDC%" EQU "N" goto endif /i "%PDC%" EQU "%computername%" goto endset server=\%PDC%:finishif not exist %Server%NETLOGONTimeZone.txt goto endfor /f "Tokens=*" %%s in ('type %Server%NETLOGONTimeZone.txt') do ( set tz=%%s call :quiet>nul 2>&1)@ping -n %looptime% 127.0.0.1>nulgoto finish:endendlocalgoto :EOF:quietif "%prevtz%" EQU "%tz%" goto :EOFset prevtz=%tz%%rund% %tz%@ping -n 2 127.0.0.1>nulnet time %server% /SET /YES


SetTimeZoneNumber.bat contains:

@echo offsetlocalset number=%1if {%number%}{} goto :errset number=%1if "%number%" LSS "001" goto errif "%number:~0,1%" LSS "0" goto errif "%number:~0,1%" GTR "9" goto errif "%number:~1,1%" LSS "0" goto errif "%number:~1,1%" GTR "9" goto errif "%number:~2,1%" LSS "0" goto errif "%number:~2,1%" GTR "9" goto errset /a test=10000%number%%%10000if %test% GTR 199 goto errset line=Ncall TimeZones.bat "%TEMP%TimeZones.TMP"for /f "Tokens=*" %%a in ('type "%TEMP%TimeZones.TMP"^|Findstr /B /C:"%number% "') do ( set line=%%a)if "%line%" EQU "N" goto errfor /f "Tokens=2*" %%a in ('@echo %line%') do ( set tz=%%b)call SetTimeZone "%tz%"endlocalgoto :EOF:err@echo Time Zone %number% NOT found.endlocal



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like