Skip navigation

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

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 2000
Reg.exe      Support Tools
Nltest.exe   Support Tools
Netdom.exe   Support Tools
Ntdsutil.exe Built-in

Windows XP and Windows Server 2003
Reg.exe      Built-in
Nltest.exe   Support Tools
Netdom.exe   Support Tools
Ntdsutil.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%\NETLOGON\TimeZone.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 off
if \{%1\}

\{\} @echo Syntax: SetTimeZone "Time Zone"&goto :EOF setlocal set OK=N set tz=%1 set tz=%tz:"=% set fnd1=findstr /I "Std Dlt" set fnd2=Findstr /L /I /C:%1 set fnd3=Findstr /B /I /X /L /C:%1 set fnd4=Findstr /E /I /X /L /C:%1 set rund=RunDLL32 shell32.dll,Control_RunDLL %SystemRoot%\system32\TIMEDATE.cpl,,/Z set qry=reg.exe query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Time 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 finish for /f "Tokens=1 Delims=. " %%d in ('nltest.exe /dclist:%USERDNSDOMAIN%^|Findstr /C:"Site:"') do ( @echo %tz%>\\%%d\NETLOGON\TimeZone.txt ) :finish endlocal


GetTimeZone.bat contains:
@echo off
setlocal
set prevtz=none
set looptime=61
set server=%logonserver%
set PDC=N
set ntds1=Ntdsutil.exe roles Connections
set ntds2=Quit "select Operation Target" "List roles for connected server" Quit Quit Quit
set rund=RunDLL32 shell32.dll,Control_RunDLL %SystemRoot%\system32\TIMEDATE.cpl,,/Z
if /i "%server:~2%" NEQ "%Computername%" goto finish
set 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 end
if /i "%PDC%" EQU "%computername%" goto end
set server=\\%PDC%
:finish
if not exist %Server%\NETLOGON\TimeZone.txt goto end
for /f "Tokens=*" %%s in ('type %Server%\NETLOGON\TimeZone.txt') do (
 set tz=%%s
 call :quiet>nul 2>&1
)
@ping -n %looptime% 127.0.0.1>nul
goto finish
:end
endlocal
goto :EOF
:quiet
if "%prevtz%" EQU "%tz%" goto :EOF
set prevtz=%tz%
%rund% %tz%
@ping -n 2 127.0.0.1>nul
net time %server% /SET /YES

SetTimeZoneNumber.bat contains:
@echo off
setlocal
set number=%1
if \{%number%\}\{\} goto :err
set number=%1
if "%number%" LSS "001" goto err
if "%number:~0,1%" LSS "0" goto err
if "%number:~0,1%" GTR "9" goto err
if "%number:~1,1%" LSS "0" goto err
if "%number:~1,1%" GTR "9" goto err
if "%number:~2,1%" LSS "0" goto err
if "%number:~2,1%" GTR "9" goto err
set /a test=10000%number%%%10000
if %test% GTR 199 goto err
set line=N
call 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 err
for /f "Tokens=2*" %%a in ('@echo %line%') do (
 set tz=%%b
)
call SetTimeZone "%tz%"
endlocal
goto :EOF
:err
@echo Time Zone %number% NOT found.
endlocal



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish