Time Sync from a BAT File

If you have a computer on your network that seems to have trouble keeping its time, you can always use a bat file to force it to sync with another computer.  The code for this is pretty straight forward, you simple have to change computername to be the hostname of the computer you want to sync against.

net time \\computername /set /y

The biggest requirement you will need is to make sure the computers use the same user name and password.  If they do not, you can always set this as a schedule task to run as another user, or make use the run as comment to run the time sync bat file as another user.  So if you had created a file called timesync.bat that used the code above, the run as command would look something like this.

runas /user:hostname\administrator /savecred c:\support\timesync.bat

You will most likely be prompted to save the password when running the runas command above, as the /savecred option is set.  You may also need to change the hostname value to be the computer name that you are running this on, and also the location of the timesync.bat file.

So if you find yourself in a situation where you need to force a computer to sync its time with another computer, these could of bat files could come in useful.