Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to set the time server from cmd and how to synchronize the clock?

11,503 views
Skip to first unread message

Timo Salmi

unread,
Jan 4, 2009, 4:49:25 AM1/4/09
to

http://www.netikka.net/tsneti/info/tscmd169.htm

169} How to set the time server from cmd and how to synchronize the
clock? (Potentially under construction)

Caveats:
1. It is assumed that the PC is not in a domain with a domain's own
centralized time server.
2. Some of the steps may be superfluous.

@echo on & @setlocal enableextensions
@echo
======================================================================
@echo Set the SNTP (Simple Network Time Protocol) source for the time
server
net time /setsntp:time.nist.gov,0x1
@echo ==================================================================
@echo Turn off and then turn on the time service to ensure that it works
net stop w32time & 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
======================================================================
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.
==================================================================
Turn off and then turn on the time service to ensure that it works
C:\_D\TEST>net stop w32time & net start w32time
The Windows Time service is stopping.
The Windows Time service was stopped successfully.
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.

References/Comments: (See the web page)

All the best, Timo

--
Prof. Timo Salmi mailto:t...@uwasa.fi ftp & http://garbo.uwasa.fi/
Hpage: http://www.uwasa.fi/laskentatoimi/english/personnel/salmitimo/
Department of Accounting and Finance, University of Vaasa, Finland
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.htm

ten.n...@virgin.net

unread,
Jan 4, 2009, 8:33:51 AM1/4/09
to
On Sun, 04 Jan 2009 11:49:25 +0200, Timo Salmi wrote:

> http://www.netikka.net/tsneti/info/tscmd169.htm
>
> 169} How to set the time server from cmd and how to synchronize the
> clock? (Potentially under construction)
>

Caution! (Ref: http://technet.microsoft.com/en-us/library/cc773263.aspx)
You should not use the Net time command to configure or set time when the
Windows Time service is running.

Matthias Tacke

unread,
Jan 4, 2009, 12:46:49 PM1/4/09
to
Timo Salmi wrote:
>
> http://www.netikka.net/tsneti/info/tscmd169.htm
>
> 169} How to set the time server from cmd and how to synchronize the
> clock? (Potentially under construction)
>
> net time /setsntp:time.nist.gov,0x1
snip

Hello Timo,
instead of propagating a single time source,
it might be better to use a more local time server
through pool.ntp.org. See <http://www.pool.ntp.org/en/use.html>

There are several zones available
- continent (http://www.pool.ntp.org/zone/@) or
- country (http://www.pool.ntp.org/zone/fi).
you can also apply more than one time server with

net time /setsntp:"0.fi.pool.ntp.org 0.europe.pool.ntp.org o.pool.ntp.org"

--
Regards
Matthias

John Gray

unread,
Jan 4, 2009, 3:14:06 PM1/4/09
to
> Prof. Timo Salmi   mailto:t...@uwasa.fi    ftp &http://garbo.uwasa.fi/

> Hpage:http://www.uwasa.fi/laskentatoimi/english/personnel/salmitimo/
> Department of Accounting and Finance,   University of Vaasa,  Finland
> Useful CMD script trickshttp://www.netikka.net/tsneti/info/tscmd.htm

To me, what seems to be missing from the batch file is an indication
of what the current correct (NTP) time is and how far out the PC clock
was before it was synchronised.

I used to use CMDTIME3.EXE from http://www.softshape.com/download/
(almost at the bottom of the page) which provides this information.

Being in the UK, I use uk.pool.ntp.org as the Internet Time Server in
Date & Time Properties - the update frequency can easily be altered
from 'every seven days' by a registry mod.

But that would be to miss the point of the 'demonstration' batch file!

Timo Salmi

unread,
Jan 4, 2009, 4:52:09 PM1/4/09
to
Matthias Tacke <Matt...@Tacke.de> wrote:
> Timo Salmi wrote:
>> http://www.netikka.net/tsneti/info/tscmd169.htm
>> 169} How to set the time server from cmd and how to synchronize the
>> clock? (Potentially under construction)

> instead of propagating a single time source,


> it might be better to use a more local time server
> through pool.ntp.org. See <http://www.pool.ntp.org/en/use.html>

Thanks Matthias. I have added the link information to the item's
references.

Timo Salmi

unread,
Jan 4, 2009, 4:56:31 PM1/4/09
to
John Gray <gga...@emailias.com> wrote:
> On 4 Jan, 09:49, Timo Salmi <t...@uwasa.fi> wrote:
>> http://www.netikka.net/tsneti/info/tscmd169.htm
>>
>> 169} How to set the time server from cmd and how to synchronize the
>> clock? (Potentially under construction)

> To me, what seems to be missing from the batch file is an indication


> of what the current correct (NTP) time is and how far out the PC clock
> was before it was synchronised.
>
> I used to use CMDTIME3.EXE from http://www.softshape.com/download/
> (almost at the bottom of the page) which provides this information.

Yes. As it happens, I have myself used that old, but very useful third
party program for years. I have added the link to the references, since
it wasn't there.

> Being in the UK, I use uk.pool.ntp.org as the Internet Time Server in
> Date & Time Properties - the update frequency can easily be altered
> from 'every seven days' by a registry mod.
> But that would be to miss the point of the 'demonstration' batch file!

I already have have a link in the item to the interval alteration:
http://www.tweakxp.com/article36948.aspx

Thanks for the feedback.

All the best, Timo

--
Prof. Timo Salmi mailto:t...@uwasa.fi ftp & http://garbo.uwasa.fi/

Timo Salmi

unread,
Jan 4, 2009, 5:02:00 PM1/4/09
to

Noted. I changed a bit the order of the commands. The link already was
there.

The English phrase from that page in itself is clear, but what is not so
clear is what actually should be done about it and what problems are
expected. The information just is too scanty on that page and issue.

ten.n...@virgin.net

unread,
Jan 4, 2009, 5:55:52 PM1/4/09
to
On Sun, 04 Jan 2009 11:49:25 +0200, Timo Salmi wrote:

> @echo Turn off and then turn on the time service to ensure that it works
> net stop w32time & net start w32time

I'm not 100% sure but I think that this would be a perfect place to use 'if
successful'

Net stop w32time && Net start w32time

tim_wood

unread,
Jan 4, 2009, 7:09:00 PM1/4/09
to
John Gray wrote:

snip

> Being in the UK, I use uk.pool.ntp.org as the Internet Time Server in
> Date & Time Properties - the update frequency can easily be altered
> from 'every seven days' by a registry mod.

I too am in the UK John, my two penneth, hope it helps.

I was slightly put off by this quote on ntp.org :-
"If your Internet provider has a timeserver, or if you know of a good
timeserver near you, you should use that and not this list - you'll
probably get better time and save resources"

Save resources, I am all for that, but they don't seem that confident
about the service, however, much of it is donated so, you get what you
pay for (or are not paying for in this case).

A loooong time ago (NT 3.5 maybe earlier) I looked into this and settled
on using the JANET time servers - http://www.ja.net/services/ntp/index.html

BTW did anyone actually notice the leap second that was added to 2008,
due to excessive wind in the wrong direction in 2008!

ftp://hpiers.obspm.fr/eop-pc/bul/bulc/leap_second.txt

Regards,

--

Tim Wood
Replace the "web" with "btinternet" to
email me directly, or reply here.

Timo Salmi

unread,
Jan 5, 2009, 2:40:46 AM1/5/09
to
tim_wood wrote:
> I was slightly put off by this quote on ntp.org :-
> "If your Internet provider has a timeserver, or if you know of a good
> timeserver near you, you should use that and not this list - you'll
> probably get better time and save resources"

Personally I have my automated time server set to my ISP's time server.
And when I want to update "manually", in fact I use the recently
discussed third party utility

cmdtime3.exe /q /t ntp.pipex.net sync

I even have a shortcut on my desktop to that using an icon from my own
collections that closely looks like this
http://lipas.uwasa.fi/~ts/gifst2/tsdigi2.gif

All the best, Timo

--
Prof. Timo Salmi mailto:t...@uwasa.fi ftp & http://garbo.uwasa.fi/

Matt Williamson

unread,
Jan 5, 2009, 9:12:24 AM1/5/09
to
>To me, what seems to be missing from the batch file is an indication
>of what the current correct (NTP) time is and how far out the PC clock
>was before it was synchronised.

>I used to use CMDTIME3.EXE from http://www.softshape.com/download/
>(almost at the bottom of the page) which provides this information.

>Being in the UK, I use uk.pool.ntp.org as the Internet Time Server in
>Date & Time Properties - the update frequency can easily be altered
>from 'every seven days' by a registry mod.

>But that would be to miss the point of the 'demonstration' batch file!

Here is how I do it.

[1]@echo off
[2]setlocal enabledelayedexpansion
[3]color 0a
[4]for /f "tokens=1 delims= " %%a in ('net view^|findstr "\\"') do (
[5] ping -n 1 %%~na|Find "TTL=" >nul && (call :checktime %%a) || echo %%~na
*Offline*
[6])
[7]goto :eof
[8]
[9]:checktime
[10]for /f "tokens=2 delims=:" %%c in ('w32tm /monitor /computers:%~n1^|find
"NTP:"') do (
[11] for /f "tokens=1" %%d in ("%%~nc") do (
[12] set n=%%d
[13] if !n:~-1! GTR 2 echo %1 : %%c
[14] )
[15])


0 new messages