NTP client configuration

From WPKG | Open Source Software Deployment and Distribution
Jump to: navigation, search

How to enable or disable NTP client on Windows.

<package id="ntp-client" name="NTP time synchronization" revision="1" priority="999" reboot="false" execute="once">
        <install cmd='cmd /c sc config w32time start= auto' />
        <install cmd='cmd /c net time /setsntp:192.168.0.1' />
        <install cmd='cmd /c net time \\192.168.0.1 /set /yes' />
        <install cmd='cmd /c net stop w32time &amp; net start w32time' />
        <install cmd='cmd /c w32tm /resync /nowait' />
        <remove cmd='cmd /c net time /setsntp:time.windows.com' />
        <remove cmd='cmd /c net stop w32time &amp; net start w32time' />
        <remove cmd='cmd /c w32tm /resync /nowait' />
</package>

Note: You must use &amp; in place of & within cmd variable expressions of the package.xml file else you get the error: "Whitespace is not allowed at this location."

or:

<package
        id="ntp-client"
        name="ntp client configuration"
        revision="1"
        reboot="false"
        priority="1"
        execute="once">
        <install cmd="%SOFTWARE%\ntp\install.bat" />
        <upgrade cmd="%SOFTWARE%\ntp\install.bat" />
        <remove cmd="%SOFTWARE%\ntp\uninstall.bat" />
</package>

install.bat:

sc config w32time start= auto
net time /setsntp:192.168.0.100
net stop w32time & net start w32time
w32tm /resync /nowait

uninstall.bat:

net time /setsntp:time.windows.com
net stop w32time & net start w32time
w32tm /resync /nowait