Skip to content

Instantly share code, notes, and snippets.

@Soulflare3
Last active May 14, 2020 23:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Soulflare3/f3a89eb9928e4f155b12ce185be630ec to your computer and use it in GitHub Desktop.
Save Soulflare3/f3a89eb9928e4f155b12ce185be630ec to your computer and use it in GitHub Desktop.
Quick & dirty time fix (no checks) for when Windows Update or booting into Linux causes my clock to mess up
sc config W32Time start=auto
sc start W32Time
sleep 5
w32tm /resync
@Soulflare3
Copy link
Author

Soulflare3 commented Apr 5, 2018

sc config W32Time start=auto configuring the Windows Time service to auto-start because apparently Windows Update can mess this up?

Because I'm not doing any fancy checking here to see if the service is already running, I just set 5 second sleep timer. I find on my PC I can reliably have the Windows Time service (W32Time) start in that time. If your PC is slower you can just make that integer larger to accommodate. I may put an actual check in the future (probably not, but one can hope).

Basically if we try to resync the clock with the network time w32tm /resync but the service hasn't finished starting, we get an error message instead and nothing happens. To prevent getting this error we wait for 5 seconds sleep 5 before attempting the time sync.

@Soulflare3
Copy link
Author

Soulflare3 commented Apr 5, 2018

I simply call this as part of my startup.bat like this:
start "" elevate64 time.bat

And I just have a shortcut to startup.bat in my start menu.
Windows start menu startup folder

I use elevate64 as a quick way to run as admin. Should work fine as long as it's in the same folder, or if it's available in your Path Variable. There are other ways to run as admin as well, but I use this one for simplicity and the ability to call it anywhere.

You can also set this to run as admin with no additional software. Simply right-click the shortcut in your start menu, go to Properties, then in the General tab hit Advanced. The window that opens should have the option to run the shortcut as admin.
Shortcut Properties - Run as Admin

If you go with this method, keep in mind you don't have to put it in an additional file, the file and shortcut would simply be time.bat (in this case) and the contents of the file would be the code at the top of the page. Then just set it to run as admin (so you can modify the properties service (AKA turn it off and on again), otherwise Windows won't let you touch it IIRC). You could try it without admin, and if it doesn't work try it with.

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