用于将 Windows 操作系统时钟同步到 NTP 服务器的便携式命令行

Cri*_*scu 6 windows command-line ntp

最近(这个千年)版本的 Windows 是否有一种“便携式”方式来强制 NTP 同步?

在 Windows 7 上,甚至还有先决条件——服务Windows Time需要运行。

(单击任务栏中的时间?更改日期和时间设置...?选择Internet 时间选项卡?更改设置?勾选同步...复选框。这将启动Windows Time服务)。

之后,从提升的命令提示符,我可以执行以下操作:

> w32tm /resync
Sending resync command to local computer
The command completed successfully.

>
Run Code Online (Sandbox Code Playgroud)

...但我不认为这是向后兼容的。Windows XP记录方式使用net time

> net time /setsntp
Run Code Online (Sandbox Code Playgroud)

...但在 Windows 7 上,这给出了错误消息:

The /QUERYSNTP and /SETSNTP options have been deprecated. Please use w32tm.exe
to configure the Windows Time Service.
Run Code Online (Sandbox Code Playgroud)

那么,无论 Windows 版本如何,有没有办法做到这一点?(如果不能用简单的命令完成,那么也许可以通过编程来完成?)

rAl*_*len 7

您应该能够在 Windows 2000 及更高版本的所有 Windows 版本上使用w32tm

我试过跑步

w32tm /resync
Run Code Online (Sandbox Code Playgroud)

在 Windows XP 和 2003 上,该命令在它们上运行没有问题。

您可以在此处看到它在 Windows XP 上受支持。

您还可以看到它在 Windows 2000 中受支持,请看这里