I have several servers hosted with GoGrid, and every time I reboot one of my cloud servers, the system clock is incorrect. The server isn’t a member of a domain, so I just have the OS set to sync with an Internet time server. This only happens once a day, and I don’t see an option to make this happen automatically upon reboot. So I’m left with writing some code to do it for me.
I created a batch file with the ‘w32tm /resync’ command, and scheduled it to run on system startup, but it doesn’t work because the network connection isn’t available when the batch file is run. How can I cause the time sync to start after the OS is fully loaded and the network connection is available? I need the time to be correct ASAP after the computer boots so timestamps in my database will be correct.
On Windows 2008, there is an option in the Task Scheduler that will allow you to wait until a network connection is available before the task is run. In the task properties dialog, create a new ‘At Startup’ trigger, and be sure to check the ‘Enabled’ box. Add an action to run your batch file. Finally, add a Condition to start the task only if the network connection is available. I then asked it to restart the command up to 3 times if it failed. That seems to work great.
On older versions of Windows, use the following batch file contents to retry the sync command until it is successful, or until it has retried too many times.