93

I need to verify the current NTP configuration on some Windows systems. Ideally, I'd like to be able to do this via command line instead of navigating through configuration screens.

(I'm working on several different OS versions, and configuration screens tend to not always be in the same place across versions.)

I'm hoping to find a quick, memorable command that I can just punch into a CMD console to get the result. A batch file I can carry around with me will do just as well, though.

Specifically, I need the following:

  • Show whether or not the system is configured to receive time from an NTP server.
  • Show the NTP server(s) the system is receiving time from.
  • Show the time of the last synchronization.
  • Show the current time on the system.

What command(s) would be necessary to achieve these results?

Looking for a solution that's cross-compatible with Windows XP, 7, Server 2003, and Server 2008.

4
  • I know to check time you can do "net time \\computername" to get the time of the remote pc. I don't think net time lets you view last sync though... however "net time ?" gives a set option, so it's like 1/2 of what your looking for. Commented May 16, 2012 at 13:26
  • @Kyle I just figured out that net time /querysntp shows the server. Getting the rest of it might be tricky.
    – Iszi
    Commented May 16, 2012 at 13:33
  • 3
    In Windows 7 net time /querysntp has been deprecated.
    – Daniel
    Commented Nov 23, 2016 at 21:12
  • You did write you didn't want to go configuration screens but why? The ntp setting is readilly available in control panel / Clock and Region / Date and Time / Internet Time.
    – theking2
    Commented Mar 3 at 14:06

6 Answers 6

106

In the command line, type

w32tm /query /configuration
w32tm /query /status
Time /T 

w32tm /query /configuration gives you the configuration you have set up.

w32tm /query /status gives you information such as:

  • stratum
  • leap indicator
  • precision
  • last sync
  • NTP server
  • poll interval

time /T outputs the current system time.

Note: w32tm /query was first made available in the Windows Time client versions of Windows Vista, and Windows Server 2008. See Windows Time Service Tools and Settings

5
  • 6
    No good on XP. "The command /query is unknown."
    – Iszi
    Commented May 16, 2012 at 16:07
  • What's the difference between time /t and the time shown on the bottom right of the taskbar?
    – Pacerier
    Commented Dec 21, 2014 at 14:11
  • For the first, w32tm /query /configuration, I get "The following error occurred: Access is denied. (0x80070005)". I think I have enough rights. Commented Dec 12, 2016 at 12:17
  • 4
    You need to be in an elevated command window for that one.
    – Phillip R.
    Commented Aug 3, 2017 at 13:51
  • 1
    On Windows 10 in admin cmd prompt: "The following error occurred: The service has not been started. (0x80070426)"
    – Navin
    Commented Dec 2, 2020 at 6:26
26

This answers your last question:

Open a command prompt and type exactly:

w32tm /stripchart /computer:NTPServerNameOrIP /dataonly /samples:x (how many returns you want)

It returns time and difference to NTP server time. If it returns time, error: 0x80072746 then that is not your NTP server.

An example of a command is below:

Command example

1
  • I think the error 0x800705B4 means you are being throttled (too many requests in the allotted time).
    – Arvo Bowen
    Commented Feb 11, 2021 at 17:11
12

I tried:

w32tm /query /status

I got:

The command /query is unknown.

In a different machine, I got:

The following error occurred: The service has not been started. (0x80070426)

Then I tried:

reg QUERY [\\machine\]HKLM\SYSTEM\CurrentControlSet\Services\W32Time

I got:

ERROR: The system was unable to find the specified registry key or value.

Then I tried:

net time /querysntp

I got:

This computer is not currently configured to use a specific SNTP server.

In another machine, I got the help page, saying also:

The /QUERYSNTP and /SETSNTP options have been deprecated. Please use w32tm.exe to configure the Windows Time Service.

So, basically, the service was not running. Following these instructions, I did:

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

Finally, all the above would work. (note: if net start fails, see below) Then I just needed to set my ntp up... I did it with:

w32tm /config /manualpeerlist:10.0.0.5 /syncfromflags:manual /reliable:yes /update

following instructions from here, but perhaps it could've been as easy as:

net time /setsntp:10.0.0.5

as instructed here. (10.0.0.5 being my local NTP server). If you're not using a local NTP server, you can use the generic one:

w32tm /config /manualpeerlist:pool.ntp.org /syncfromflags:manual /reliable:yes /update

Finally, you might need to do the following, which was not necessary for me:

w32tm /config /update
w32tm /resync /rediscover

NOTE: if net start w32time fails with error 1290 (The service start failed since one or more services in the same process have an incompatible service SID type setting) then follow the steps here:

w32tm /unregister
w32tm /register
sc config w32time type= own
net start w32time

Then follow as above.


NOTE 2: if the NTP service doesn't automatically start on reboot, it might be due to its start settings, as described here: depending on your windows, it might be set to start only when it joins a domain. You can check with:

sc qtriggerinfo w32time

If it's configured to start when you join a domain, and you don't have a domain set up in your machine, it will not start the service and set the time. It probably doesn't join a domain because you don't want it to. In any case, just change which trigger starts it. For example, to start when the machine has network (and therefore is able to access the server), do:

sc triggerinfo w32time start/networkon stop/networkoff
6

From the command line you can get the info like this:

reg QUERY [\\machine\]HKLM\SYSTEM\CurrentControlSet\Services\W32Time\Parameters
reg QUERY [\\machine\]HKLM\SYSTEM\CurrentControlSet\Services\W32Time\Config

Seems like that should be enough at least to get going in that direction, that is, if I understood your question. AFAIK, the 'reg' command works on all these different platforms so long as you have the right services running.

2
  • 1
    I got: "ERROR: The system was unable to find the specified registry key or value." It turns out W32Time was not started...
    – msb
    Commented Mar 13, 2015 at 22:21
  • 1
    So "[\\machine\]" means it can be left out if on the same machine? Commented Dec 12, 2016 at 12:14
6

Use:

net stop w32time
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"
net start w32time
w32tm /config /update
w32tm /resync /rediscover

A .bat sample file is at https://gist.github.com/thedom85/dbeb58627adfb3d5c3af.

I also recommend this program: http://www.timesynctool.com/

3

Take a look at the w32tm command-line tool. It can set and query the configuration and report a /stripchart of the time offset with another computer.

5
  • 1
    The /query option is not available on XP.
    – Iszi
    Commented May 16, 2012 at 16:08
  • 5
    Try net time /querysntp.
    – Fran
    Commented May 16, 2012 at 17:10
  • 1
    @Fran That works. I was hoping to get one command that was cross-platform, but it seems I might have to use two different ones - or write a batch file that includes platform detection to determine which command(s) to run.
    – Iszi
    Commented May 16, 2012 at 17:14
  • 2
    @lszi In my scripts, I test for the existence of C:\users. If I find that folder, I know I'm on a post-XP box.
    – Fran
    Commented May 16, 2012 at 19:24
  • 1
    @Fran Could you write your own answer that includes both commands? Also, what command would I use to check the last successful sync time for XP?
    – Iszi
    Commented Jun 6, 2012 at 19:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .