Setting time remotely

Remote Time Synchronization

I have written before about keeping the time on computers synchronized with an authoritative time server.  There may be times, however, when for some reason a computer is not synchronizing, and the time has drifted.

If that is the case, and there is no one available at the computer to manually set the time, and you can not log in via remote desktop, what can be done?  

Well, there are a couple of components to doing this.  First, is the ability of a Windows computer to set its time to the time on another Windows computer.  This is accomplished via the "net time" command.  Specifically, the command:

     net time \\COMPUTER /set /yes

This will set the time on the computer to be the same as the time on the computer specified (\\COMPUTER) in this example.  So, that is how the time can be set, but in our scenario, there is no one at the remote computer to run that command.  The solution to this, is to us the "AT \\REMOTECOMPUTER HH:MM:SS" command.

The "AT" command will run the command specified, on the remote computer, at a specific time.  The first thing to do in our case, is to find out what time the remote computer thinks it is.  Here we use the "net time" command, to the remote:

     net time \\REMOTECOMPUTER

This will return the time that \\REMOTECOMPUTER clock currently has.  So, if the remote computer responds that it is 9:15 AM, that is the basis that we need for the "AT" command.  I usually put the command to run a couple minutes in the future, so if the remote thinks it is 9:15 AM, I would submit the command to run at 9:17 AM.

So, the "AT" command would be:

     AT \\REMOTECOMPUTER 09:17:00 /interactive "net time \\LOCALCOMPUTER /set /yes"

To break this down:

     The \\REMOTECOMPUTER is being told to run a command at 9:17 AM
     It is to be allowed to interact with the desktop if needed (/interactive)
     The command that it is to run at that time is enclosed in quotes  
          The \\REMOTECOMPUTER will use "net time" and contact \\LOCALCOMPUTER
          It will then set its time to the \\LOCALCOMPUTER time (/set)
          and not ask for confirmation (/yes)

The result is, at what the remote computer thinks is 9:17 AM, it will set its time to that of the local computer.  Assuming the local computer actually has the correct time, then both computers end up with the correct time.


Leave a Reply