一台老服务器 时间老是不准,设置好后 只要一断电就恢复1970年,不准确数据全不对,换过3.3v电池也是,怀疑是晶振以及外围电路坏了,于是写了这款工具。目前使用了几天,没有任何问题。使用py开发的,体积有点大,下如果有问题下次再用c写个。有刚才需求的拿去。
第二版本:大约60代码使用AI生成,windows服务部分 手动修改。软件运行后会 生成 time_sync_config.json和last_time.json文件,一个配置,一个时间戳,想实现的功能是在单台电脑,无网络下,通过人为给出条件,保证时间戳来完成校时(这种精度差)
优化上一版本 线程问题。
原理参考:
[Asm] 纯文本查看 复制代码
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer]
"Enabled"=dword:00000001
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config]
"AnnounceFlags"=dword:00000005
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters]
"Type"="NTP"
"LocalNTP"=dword:00000001
@echo off
echo 配置本机为局域网时间服务器...
net stop w32time
w32tm /unregister
w32tm /register
net start w32time
w32tm /config /manualpeerlist:"" /syncfromflags:manual /reliable:YES /update
w32tm /resync
echo 完成配置。
pause
客户端 :
[Asm] 纯文本查看 复制代码
@echo off
echo 正在配置本机同步时间...
net stop w32time
w32tm /unregister
w32tm /register
net start w32time
w32tm /config /manualpeerlist:"xxx.xxx.xxx.xxx" /syncfromflags:manual /update
w32tm /resync
echo 已同步完毕。
pause
schtasks /create /tn "TimeSyncHourly" /tr "w32tm /resync" /sc hourly /ru SYSTEM
可作为客户端和服务端,解决有些环境下目标电脑无法联网或者不允许联网的情况,可把另一个当作服务器给其它设备同步。
命令:在cmd窗口中输入w32tm /stripchart /computer:127.0.0.1 ,如果有回显则服务正常
调用的服务:启动和关闭windows NTP的方式,还可以使用命令行来管理
启动:net start w32time
停止:net stop w32time
[url=]image.png[/url]
[url=]image.png[/url]
下载:https://webtag.lanzoue.com/immXM2u4k13g 密码:52pj
第二版本下载地址:
下载:https://webtag.lanzoue.com/iq5o12u8ehna 密码:52pj