Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a way I can synchronize the system clock with an Internet Time server (i.e: time.nist.gov) via command-line? Preferably, this should be something executable via BAT or PowerShell script.

This particular need arises because I have some VMs for which I regularly use the "save machine state" function, and these don't typically re-synchronize their clocks when I "wake" them. Often times, I'll re-load them to find the clock is (and is staying) days out-of-synch.

Re-synching the clock through the Internet Time Settings dialog usually works fine, but it takes a lot of mouse-clicking to do this. I'd much rather just keep a script on the desktop that I can double-click and have the job done for me.

Right now this is for a system running Windows 7 Home x64, but backward-compatibility to XP SP3 would be nice to have.

share|improve this question
1  
Most VM software (Virtual PC, VirtualBox) comes with drivers ("Additions") that keep the guest's clock in sync with host, among other things. –  grawity Aug 15 '11 at 20:46
    
@grawity - Using those, but it doesn't seem to do the job. –  Iszi Aug 15 '11 at 21:08

2 Answers 2

up vote 8 down vote accepted

See the reference for W32tm, "A tool used to diagnose problems occurring with Windows Time": http://technet.microsoft.com/en-us/library/bb491016.aspx. Also, w32tm /?

Use w32tm /resync. You may also need to set a server with net time if you haven't done that yet.

share|improve this answer
1  
Okay, I did... @echo off && w32tm /resync && PAUSE Threw that in a BAT file, and set a shortcut on the desktop with "Run as administrator" checked. Thanks! –  Iszi Aug 15 '11 at 21:09
    
On Windows 7, when I do this I get: The following error occurred: The service has not been started. –  User Feb 12 '13 at 0:33
    
@echo off && w32tm/resync - Command propmpt says that it does not recognize command (w32tm) –  Arpit Parekh Oct 3 at 18:01
    
.. The command I could not run on windows 7. –  Arpit Parekh Oct 3 at 18:12
    
@Iszi My mistake, actually I just have to select command prompt as Run as administrator. The command is working very fine. Thanks –  Arpit Parekh Oct 3 at 18:43

I used to do it with the net command.

for ntp

net time ntp.server.foo

for windows

net time \\server

I can't recall if you needed some sort of /ntp flag for the ntp... it will tell you if you do.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.