@echo on & @setlocal enableextensions
@echo =========================
@echo Turn off the time service
net stop w32time
@echo ======================================================================
@echo Set the SNTP (Simple Network Time Protocol) source for the time server
net time /setsntp:time.nist.gov,0x1
@echo =============================================
@echo ... and then turn on the time service back on
net start w32time
@echo =============================================
@echo Tell the time sync service to use the changes
w32tm /config /update
@echo ===========================================
@echo Display the currently configured NTP server
net time /querysntp
@echo =======================================================
@echo Reset the local computer's time against the time server
w32tm /resync /rediscover
@endlocal & @goto :EOF
The output could be e.g.:
C:\_D\TEST>cmdfaq
=========================
Turn off the time service
C:\_D\TEST>net stop w32time
The Windows Time service is stopping.
The Windows Time service was stopped successfully.
======================================================================
Set the SNTP (Simple Network Time Protocol) source for the time server
C:\_D\TEST>net time /setsntp:time.nist.gov,0x1
The command completed successfully.
=============================================
... and then turn on the time service back on
C:\_D\TEST>net start w32time
The Windows Time service is starting.
The Windows Time service was started successfully.
=============================================
Tell the time sync service to use the changes
C:\_D\TEST>w32tm /config /update
The command completed successfully.
===========================================
Display the currently configured NTP server
C:\_D\TEST>net time /querysntp
The current SNTP value is: time.nist.gov,0x1
The command completed successfully.
=======================================================
Reset the local computer's time against the time server
C:\_D\TEST>w32tm /resync /rediscover
Sending resync command to local computer...
The command completed successfully.
If the Windows time service refuses to co-operate it may be necessary
to give it a heftier wake-up call:
@echo off & setlocal enableextensions
net stop w32time
w32tm.exe /unregister
w32tm.exe /unregister
w32tm /register
net start w32time
endlocal & goto :EOF
The output could be e.g.
C:\_D\TEST>cmdfaq
The Windows Time service is stopping.
The Windows Time service was stopped successfully.
The following error occurred: Access is denied. (0x80070005)
W32Time successfully registered.
W32Time successfully registered.
The Windows Time service is starting.
The Windows Time service was started successfully.