How can I sync the computer's clock upon startup?
In Windows 10, I went to services and enabled "Windows Time" service w32time
to be automatic, that solved it for me.
My issue occured because I have a dual boot with Linux and for some reason Windows's clock is always off after I boot in Linux.
On Windows 2008, there is an option in the Task Scheduler that will allow you to wait until a network connection is available before the task is run. In the task properties dialog, create a new "At Startup" trigger, and be sure to check the "Enabled" box. Add an action to run your batch file. Finally, add a Condition to start the task only if the network connection is available. I then asked it to restart the command up to 3 times if it failed. That seems to work great.
On older versions of Windows, use the following batch file contents to retry the sync command until it is successful, or until it has retried too many times.
REM *** Retry for up to 15 minutes (90 retries @ 10 seconds each)
set retryCount=0
:SyncStart
if %retryCount == 90 goto SyncEnd
set /A retryCount=retryCount + 1
REM *** Resync the system clock
w32tm /resync
if errorlevel 1 goto SyncDelay
if errorlevel 0 goto SyncEnd
:SyncDelay
REM *** If unsuccessful, delay 10 seconds, then retry
choice /n /t:y,10>nul
goto SyncStart
:SyncEnd
As pointed out here this may be related to having a dual boot system with windows 10 and linux.
In my case the service was set to be run only manually and therefore was never triggered as one would suspect. Adjusting the service to be run automatically on startup within the services administration of windows solved the issue for me.