如何使用Batch更新Windows日期和时间?

时间:2017-05-15 15:52:49

标签: batch-file

我作为技术人员工作,有时我们重新安装操作系统。我有一个批处理脚本文件,可以处理大部分初始设置(比如安装Chrome等)。但是,我想将Windows日期和时间设置为自动。这可以使用Batch吗?

3 个答案:

答案 0 :(得分:1)

根据Explorer09的建议,您可以通过注册表更改“Internet时间设置”。

:: Enables the option: "Synchronize with an Internet time server"
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\W32Time\Parameters" /v "Type" /t reg_sz /d "NTP" /f

:: Sets the name of the NTP server to "time.windows.com"
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\W32Time\Parameters" /v "NtpServer" /t reg_sz /d "time.windows.com,0x9" /f

也可以手动设置日期和时间。

date 05-17-2017
time 19:40:00

答案 1 :(得分:1)

Windows Powershell可能有一种方法可以做到这一点;但是,我觉得这将是非常困难的,并且不那么容易获得。此外,尝试使用Batch似乎更遥不可及。但是,您所指的自动选项很可能是Windows中某个选项。因此,建议使用Powershell。

答案 2 :(得分:0)

我相信您正在寻找的答案详见http://www.robvanderwoude.com/datetime.php