跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[分享创造] 拯救烦人的 Windows 时间同步

发表于

非技术贴,小白用 GPT 解决的,GPT 代码警告
用途:懒人,clash 设置了系统代理,电脑关机的时候不会自动关闭系统代理,导致开机的时候系统时间经常同步失败
而 Windows 设置也是反人类,控制面板同步时间需要点两遍,第一遍报错第二遍才能同步时间
clash 的自启动会让核心异常,出现异常时候设置为系统代理会都不能上网,只能重启/关闭自启动解决,我选择了后者。
不会代码,也没有什么人去解决这个问题
使用的 NTP 服务器:ntp6.aliyun.com
参考文档: https://learn.microsoft.com/zh-cn/windows-server/networking/windows-time-service/windows-time-service-tools-and-settings?tabs=config
时间同步命令由文心一言工具箱读上述文档后编写,直接编写的 bat 不能同步时间,openai 写的代码也是这样子的。
记得使用 ANSI 编码保存文件

@echo off    
SETLOCAL EnableDelayedExpansion    
  
:: 尝试提升权限    
net session >nul 2>&1    
if %errorLevel% neq 0 (    
    echo 请求管理员权限...    
    powershell -Command "Start-Process -FilePath '%0' -Verb RunAs"    
    exit /b    
)    
  
echo 正在配置并同步时间...    
  
:: 停止 Windows Time 服务    
net stop w32time    
  
:: 配置 NTP 服务器为 ntp6.aliyun.com    
w32tm /config /syncfromflags:manual /manualpeerlist:"ntp6.aliyun.com"    
  
:: 启动 Windows Time 服务    
net start w32time    
  
:: 立即触发时间同步    
w32tm /resync    
  
:: 等待同步完成并检查结果    
timeout /t 3    
w32tm /query /status    
  
:: 输出同步后的时间  
echo 同步后的时间为:%date% %time%  
  
:: 等待 2 秒后关闭命令提示符窗口  
timeout /t 2 /nobreak >nul  
exit  
  
ENDLOCAL

如果跟我一样还是懒人,可以再写个同时启动 clash 和同步时间的命令。
这个命令由 gpt4turbo 所写,文心一言工具箱所写的代码不能正常请求管理员,需要右键管理员运行才能正常使用
这个代码检测是否为管理员,若不是管理员再请求权限
同样记得使用 ANSI 编码保存。

@echo off
:: 检测管理员权限
net session >nul 2>&1
if %errorlevel% == 0 (
    echo 运行中...
) else (
    echo 请求管理员权限...
    :: 创建 VBS 脚本以提升权限
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
    "%temp%\getadmin.vbs"
    :: 删除临时 VBS 脚本
    del "%temp%\getadmin.vbs"
    exit
)

:: 以管理员权限启动程序
start "" "这里写 clash 路径"
start "" "这里写同步时间的命令"

:: 执行完后关闭命令窗口
exit

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.