Windows – Portable command-line for syncing Windows OS clock to an NTP server

command linentpwindows

Is there a "portable" way across recent (this millennium) versions of Windows for forcing an NTP synchronisation?

On Windows 7, there are even prerequisites – the service Windows Time needs to be running.

(Click the time in the taskbar → Change date and time settings… → select tab Internet timeChange settings → tick Synchronize… checkbox. This will start the Windows Time service).

After that, from an elevated command prompt, I can do:

> w32tm /resync
Sending resync command to local computer
The command completed successfully.

>

… but I don't think that's backward compatible. The documented way for Windows XP uses net time:

> net time /setsntp

…but on Windows 7 this gives the error message:

The /QUERYSNTP and /SETSNTP options have been deprecated. Please use w32tm.exe
to configure the Windows Time Service.

So, is there a way to make this happen regardless of Windows version? (If it can't be done in a simple command, then maybe programmatically?)

Best Answer

You should be able to use w32tm on all the Windows versions from Windows 2000 and on.

I tried running

w32tm /resync

on Windows XP and 2003, and the command works on them with no problem.

You can see here it is supported on Windows XP.

Also you can see it is supported in Windows 2000, look here.

Related Question