批处理脚本NTP服务Windows操作系统时间同步设置

脚本如下:
///创建时间同步服务
@echo off
@echo off&&@chcp 65001>nul
setlocal enabledelayedexpansion

:: 设置版本号
set "o=cls&echo "&set “z=&&echo.&echo 按任意键或等待15秒后自动退出本界面&&timeout /t 15&&exit”
mode con lines=10 cols=60&&net session 1>NUL 2>NUL || goto tips

set “version=v8”
echo 本程序版本号: %version%

:: 显示功能选项
set “choice=”
set "tm= 本机的 时间服务 "&set “w=,请稍候…”&set “n=TimeSyncLC”
echo 你选择了“安装时间服务”,开始执行…
title 配置测试%tm%
call :Add_W32time

:Add_W32time
%o% 正在配置%tm%%w%

nul 2>&1 (
netsh advfirewall firewall delete rule %n%
netsh advfirewall firewall add rule name=%n% action=allow protocol=UDP localport=123 dir=in
reg add “HKLM\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer” /v “Enabled” /t REG_DWORD /f /d “1”
reg add “HKLM\SYSTEM\CurrentControlSet\Services\W32Time\Config” /v “AnnounceFlags” /t REG_DWORD /f /d “5”
sc start w32time
ping -n 2 ::1
sc config w32time start= auto
net stop w32time
net start w32time
ping -n 2 ::1
)
call :Test_w32time 3
if %errorlevel%==0 (
color 0A&set “x=正常。”
) else (
color 0C&set “x=异常!请联系 系统管理员 进一步处理!”
)
%o%%tm%%x%%z%
exit /b 0

:Test_w32time
%o% 正在测试%tm%%w%
for /f “tokens=*” %%a in (‘w32tm /stripchart /computer:::1 /samples:%~1 2>&1’) do set “result=%%a”
echo %result% | find “d:+” >nul
exit /b

:tips
%o% 疑似权限故障,请单击本文件右键中的 以管理员身份运行。%z%
)

endlocal
pause

///

移除时间服务

@echo off
@echo off&&@chcp 65001>nul
setlocal enabledelayedexpansion

:: 设置版本号
set "o=cls&echo "&set “z=&&echo.&echo 按任意键或等待15秒后自动退出本界面&&timeout /t 15&&exit”
mode con lines=10 cols=60&&net session 1>NUL 2>NUL || goto tips

set “version=v1”
echo 本程序版本号: %version%

:: 显示功能选项
set “choice=”
set "tm= 本机的 时间服务 "&set “w=,请稍候…”&set “n=TimeSyncLC”
echo 你确认了执行“移除时间服务” ,开始执行…
title 配置测试%tm%
call :clear_w32time

:clear_w32time
%o% 正在清除%tm%%w%

nul 2>&1 (
netsh advfirewall firewall delete rule %n%
reg add “HKLM\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer” /v “Enabled” /t REG_DWORD /f /d “0”
reg add “HKLM\SYSTEM\CurrentControlSet\Services\W32Time\Config” /v “AnnounceFlags” /t REG_DWORD /f /d “10”
sc stop w32time
ping -n 2 ::1
sc config w32time start= disabled
net stop w32time
ping -n 2 ::1
)
%o%%tm%%x%%z%
exit /b 0

:tips
%o% 疑似权限故障,请单击本文件右键中的 以管理员身份运行。%z%
)

endlocal
pause

你可能感兴趣的:(windows,自然语言处理)