Windows系统自建NTP校时服务器

2026-11-20 09:59:42 admin 8

@echo off

chcp 65001 >nul

echo ======================================

echo          Windows NTP校时服务器配置

echo ======================================

echo.

:: 检查管理员权限

net session >nul 2>&1

if %errorlevel% neq 0 (

    echo ❌ 请右键,以管理员身份运行!

    pause

    exit /b

)

echo [1] 停止Windows时间服务

net stop w32time


echo [2] 写入注册表 - 启用NTP服务器

reg add "HKLM\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer" /v Enabled /t REG_DWORD /d 1 /f

reg add "HKLM\SYSTEM\CurrentControlSet\Services\W32Time\Config" /v AnnounceFlags /t REG_DWORD /d 5 /f

echo [3] 设置w32time自动启动

sc config w32time start= auto

echo [4] 防火墙放行UDP 123端口(NTP端口)

netsh advfirewall firewall show rule name="NTP Server UDP123" >nul 2>&1

if %errorlevel% neq 0 (

    netsh advfirewall firewall add rule name="NTP Server UDP123" dir=in action=allow protocol=UDP localport=123 remoteip=any enable=yes profile=any

    echo ✅ 防火墙规则已添加

) else (

    echo ⚠️ 防火墙NTP规则已存在

)

echo [5] 启动时间服务并更新配置

net start w32time

w32tm /config /update

w32tm /resync /nowait

echo.

echo ✅ 配置完成!

echo

与我们联系
庆阳正宏商贸有限责任公司
庆阳市西峰区弘化东路由佳苑小区南门
售后与技术支持热线:18919342855(同微信)
电话咨询
邮件咨询
在线地图
QQ客服