一、只有一台NTP服务器的配置脚本方法:
#将分隔线以下代码复制到记事本,文件格式另存为.bat格式。即可实现时间自动同步及同步频率参数设置,可批量执行于较多终端设备上,以替代手工设置windows同步操作。
#红色字体192.168.0.11为NTP时间服务器地址,绿色字体3600为同步频率,秒单位,即1小时。
#分隔线
-------------------------------------------------------------------------------------------------
@echo off
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
@echo off
net stop w32time
w32tm /unregister
w32tm /register
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers" /ve /t REG_SZ /d 1 /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers" /v 1 /t REG_SZ /d 192.168.0.11 /f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters" /v NtpServer /t REG_SZ /d "192.168.0.11,0x9 /f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient" /v SpecialPollInterval /t REG_DWORD /d 3600 /f
ping -n 3 127.0.0.1 >nul
sc config W32Time start= auto
ping -n 6 127.0.0.1 >nul
sc config W32Time start= delayed-auto
ping -n 6 127.0.0.1 >nul
net start W32Time
@echo ********************************************************************
@echo NTP-Server:192.168.0.11 3600S OK
@echo ********************************************************************
ping -n 3 127.0.0.1 >nul
w32tm /resync
exit
-------------------------------------------------------------------------------------------------
二、两台NTP服务器的配置脚本方法:
#将分隔线以下代码复制到记事本,文件格式另存为.bat格式。即可实现时间自动同步及同步频率参数设置,可批量执行于较多终端设备上,以替代手工设置windows同步操作。
#红色字体192.168.0.11,192.168.0.12为两台NTP时间服务器地址,绿色字体3600为同步频率,秒单位,即1小时。
#分隔线
-------------------------------------------------------------------------------------------------
@echo off
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
@echo off
net stop w32time
w32tm /unregister
w32tm /register
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers" /ve /t REG_SZ /d 1 /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers" /v 1 /t REG_SZ /d 192.168.0.11 /f
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers" /v 2 /t REG_SZ /d 192.168.0.12 /f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters" /v NtpServer /t REG_SZ /d "192.168.0.11,0x9 192.168.0.12,0x9" /f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient" /v SpecialPollInterval /t REG_DWORD /d 3600 /f
ping -n 3 127.0.0.1 >nul
sc config W32Time start= auto
ping -n 6 127.0.0.1 >nul
sc config W32Time start= delayed-auto
ping -n 6 127.0.0.1 >nul
net start W32Time
@echo ********************************************************************
@echo NTP-Server:192.168.0.11/192.168.0.12 3600S OK
@echo ********************************************************************
ping -n 3 127.0.0.1 >nul
w32tm /resync
exit