ccoxtn
ccoxtn

Reputation: 1602

How can I sync the computer's clock upon startup?

I have several servers hosted with GoGrid, and every time I reboot one of my cloud servers, the system clock is incorrect. The server isn't a member of a domain, so I just have the OS set to sync with an Internet time server. This only happens once a day, and I don't see an option to make this happen automatically upon reboot. So I'm left with writing some code to do it for me.

I created a batch file with the "w32tm /resync" command, and scheduled it to run on system startup, but it doesn't work because the network connection isn't available when the batch file is run. How can I cause the time sync to start after the OS is fully loaded and the network connection is available? I need the time to be correct ASAP after the computer boots so timestamps in my database will be correct.

Upvotes: 63

Views: 99953

Answers (12)

trindflo
trindflo

Reputation: 349

Use task scheduler to create a basic task. Run with highest privileges at System Startup. Start program c:\windows\system32\cmd.exe then set the optional arguments to /C w32tm /resync

The Windows Time service must also be running, so set that to automatic as mentioned in some of the other suggestions.

Upvotes: 3

R Sh
R Sh

Reputation: 11

In my Case with dual windows/linux boot, time wasn't getting synced on Windows, Even when "Windows Time" was set to "Automatic". Changing it to "Automatic (Delayed Start)" fixed it for me - The time gets synced about 1 minute after Windows starts.

Upvotes: 0

Sergio Perez
Sergio Perez

Reputation: 641

I use this batch script for resync Windows time: Must be run as administrator

w32tm /unregister
w32tm /register
net start w32time
w32tm /resync

Upvotes: 1

syamsir vj
syamsir vj

Reputation: 21

i try w32sync with option automatic (delayed start) and that is solved for me ....

Upvotes: 1

user2265240
user2265240

Reputation: 465

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.

enter image description here

Upvotes: 44

Stuart
Stuart

Reputation: 1

I should have realized that I needed to run this batch file as an administrator for it to work, but once I figured that out, I only had to make a minor adjustment to the choice command for it to work like a charm.

choice /n /t:10 /D:y

Like the above user, I too have a dual boot between Ubuntu 18.04 and Windows 7, where booting to Ubuntu set's the System Clock to UTC and the OS adjusts for GMT, whereas it looks like Windozz sets the system clock to the time zone.

Setting to the task scheduler was easy enough, my only specific issue is that I have my laptop connect to my FritzBox for time, so I guess my updates will only happen when I'm at home. (Its' easy enough to swap the NTP back to one of the presets, so I'm not concerned)

Upvotes: -1

Craig
Craig

Reputation: 1801

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.

Upvotes: 180

equiman
equiman

Reputation: 8142

Open a terminal (as Admin) and run this command:

Use this on your home computer or not joined to domain
w32tm /resync

Use this if you are joined to domain
net time /domain

If you get a The service has not been started. (0x80070426) error, then it means that you need to start the Windows Time service, wait a minute, and try again.

If you get a The computer did not resync because no time data was available error, then you should be able to try again until successful.

Windows 10: Synchronize Clock with an Internet Time Server in Windows 10

Upvotes: 5

scrappylaptop
scrappylaptop

Reputation: 9

Found this semi-randomly. New choice.exe syntax for Win 7+ to insert a 10-second pause

choice /N /T 10 /D y>nul

Upvotes: -2

Ian Jacobs
Ian Jacobs

Reputation: 5501

scheduled task that runs on login maybe?

EDIT: you may want to put a 30 second or so hold in the script to allow for the network connections to refresh. Totally didn't read your question right.

Upvotes: 1

ccoxtn
ccoxtn

Reputation: 1602

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

Upvotes: 19

Stever B
Stever B

Reputation: 4117

Normally the Windows Time Service should take care of this for you.

http://technet.microsoft.com/en-us/library/cc773013.aspx

Do you have the service running?

Upvotes: 8

Related Questions