Thursday, February 24, 2011

Windows 2003 time synchronization - to external time source

Although this isn't in my primary focus, time synchronization with external time source is very important. This is especially important for Windows domain environments, but also for larger systems in workgroups. I searched everywhere for this simple information - how to sync clock of the Windows computer(s) in workgroup to some external time source i.e. ntp servers?

I know that this looks simple - but if you really tried to find relevant information for this case, you will usually start at Microsoft Technet or Windows command line (w32tm tool) and eventually end up on user forums browsing through articles or posting questions why this doesn't work. There are several way to do this - one is using Windows Time and Date from control panel (or by doubleclicking on clock on the taskbar). Second way is by changing some setting in registry and using command line and the third way is by using command line. This third way is what I will show you. I find that using command line is best for me - since I can control and validate synchronization process. Benefits of using scripts are:
  • Control the start process
  • Schedule the sync job
  • Log synchronization results in txt file
  • Log synchronization results in Event Viewer (System)
What you will need?

Of course, I assume that you are using Windows 2003 in workgroup environment. You will need Internet connection in order to access time servers and you need to choose the time server you like. Usually, this is NTP server, time server in your country or at least in your time zone. You can search on the internet for available time servers. Last but not the least - if you are connected to some kind of corporate local network with firewall - you need to ensure that UDP port 123 is open for traffic originating from internal network to the internet.

Anyway, since I live in Croatia I will be using one of the local NTP/time servers "zg1.ntp.carnet.hr". Before running sync job, let's check/notice the time difference you have now between your computer clock and correct time showed by one of the time servers in your area. Now, create the batch file with following lines:

w32tm /config /manualpeerlist:zg1.ntp.carnet.hr,0x8 /syncfromflags:MANUAL /reliable:yes
w32tm /config /update
net stop w32time
net start w32time
w32tm /resync /rediscover

You should save this file on your disk and test if this script work for your computer.
After you run this script - you should notice this change i.e. that the time on your computer is now correct.

Hope this helps! :)