Skip to content

Instantly share code, notes, and snippets.

@thedom85
Last active January 18, 2026 01:21
Show Gist options
  • Select an option

  • Save thedom85/dbeb58627adfb3d5c3af to your computer and use it in GitHub Desktop.

Select an option

Save thedom85/dbeb58627adfb3d5c3af to your computer and use it in GitHub Desktop.
Rem run as administrator
@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
w32tm /config /syncfromflags:manual /manualpeerlist:"0.it.pool.ntp.org 1.it.pool.ntp.org 2.it.pool.ntp.org 3.it.pool.ntp.org"
@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 Reset the local computer's time against the time server
w32tm /resync /force /rediscover
@endlocal & @goto :EOF
@Dimon1358

Copy link
Copy Markdown

Thanks!

@Baanin

Baanin commented Apr 25, 2017

Copy link
Copy Markdown

Thanks

@yangloc

yangloc commented May 22, 2017

Copy link
Copy Markdown

Thanks a lot!

@mathandy

mathandy commented Jun 3, 2017

Copy link
Copy Markdown

To others: make sure you "run as admin".
@thedom85 Thanks!

@rlogan403

Copy link
Copy Markdown

Thanks.

@z00sts

z00sts commented Mar 12, 2018

Copy link
Copy Markdown

👍

@benjamin238

Copy link
Copy Markdown

👍

@ediband

ediband commented Feb 21, 2019

Copy link
Copy Markdown

Great script, thx!

@truekenny

Copy link
Copy Markdown

Work on Win10

@johnnyfortner

Copy link
Copy Markdown

Thank you, now I can keep time!

@ahmedmoselhi

Copy link
Copy Markdown

can i make a scheduled task using this?

@domenicozinzidea

Copy link
Copy Markdown

@ahmedmoselhi Yes, you can.

@kristianrl

Copy link
Copy Markdown

If you need to run this every time the computer boots, press the Windows key + R, type shell:startup. Then you can create a shortcut. Enter the shortcut's Properties, click Advanced, and select Run as administrator.

@kristianrl

Copy link
Copy Markdown

The clock was months off on my old computer, so Windows wouldn't update the time. This can be fixed by invoking w32tm /resync /force . Will you consider updating the script, @thedom85?

@thedom85

thedom85 commented Mar 7, 2024

Copy link
Copy Markdown
Author

@kristianrl I added this command "w32tm /resync /force /rediscover" at the end

@valentinaballara

Copy link
Copy Markdown

@thedom85 Thank you very much! It was very useful.

@AndisGrossteins

Copy link
Copy Markdown

Running w32tm /config command after stopping the w32time service would always fail because w32tm command communicates with the service using RPC calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment