首页 > 解决方案 > 如何在 Windows 中自动同​​步日期和时间?

问题描述

我想编写一个 .bat 文件,我可以在 Windows 中使用任务计划程序进行计划。该脚本应打开时间设置并自动单击同步选项,如下所示:

在此处输入图像描述

到目前为止,我可以使用以下代码行打开此窗口:

start ms-settings:dateandtime

但是我不知道如何单击“立即同步”按钮。

你知道完成这项任务的聪明而优雅的方法吗?如果最终结果相同,请随意提出完全不同的方法。

标签: windowsbatch-filetimecmdsynchronization

解决方案


w32tm /resync 必须由管理员运行,否则您会收到拒绝消息

有关其他选项的更多详细信息,请参阅https://docs.microsoft.com/en-us/windows-server/networking/windows-time-service/windows-time-service-tools-and-settings

w32tm /resync
Sending resync command to local computer
The following error occurred: Access is denied. (0x80070005)

在此处输入图像描述

然后在域上使用

w32tm /domain

想要使用与默认不同的服务器?然后替换time.server.com

w32tm /config /update /manualpeerlist:time.server.com

在此处输入图像描述

https://www.ntppool.org/en/use.html


推荐阅读