【问题标题】:How to automatically sync Date & Time in windows?如何在 Windows 中自动同​​步日期和时间?
【发布时间】:2021-11-01 17:37:27
【问题描述】:

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

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

start ms-settings:dateandtime

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

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

【问题讨论】:

  • 批处理文件无法与 GUI 交互...
  • 哦,好的,谢谢您的回复! :) 请问您还有其他选择吗?
  • 好吧,powershell 应该是一个可能的选择……

标签: windows batch-file time cmd synchronization


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2018-01-06
    • 1970-01-01
    • 1970-01-01
    • 2014-03-27
    • 2015-05-17
    • 2014-05-16
    • 2019-07-22
    • 2018-09-05
    • 1970-01-01
    相关资源
    最近更新 更多