简体   繁体   中英

Setting internet time server on windows embedded standard through batch or similar

I have a PLC running windows embedded standard where I make some installations and modifications specific to my company's software as part of our installation process (which is all manual today). I'm now in the process of automating this procedure.

I want to set the Date and time properties->internet time server to pool.ntp.org through a batch file or similar. The command

w32tm

is not recognized. I've tried using the command

net time /setsntp:pool.ntp.org

which returns

the command completed succefully. .

Using the command

net time /querysntp

also returns

The current SNTP value is: pool.ntp.org The command completed successfully.

But these changes are not reflected when I manually check them under Date and time properties->internet time server, not even after a restart. So I'm left wondering if the command I'm using is actually working? Is there another way to accomplish this?

EDIT: The following .bat file works. The changes in the registry alone only added the server to the list and made it default but it didn't enable syncing. REG ADD HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Servers /v "0" /t REG_SZ /d "pool.ntp.org" /f REG ADD HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Servers /ve /d "0" /f NET TIME /setsntp:pool.ntp.org

Have a look in regedit under the following path;

HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\DateTime\\Servers

Add your server(s) into that folder as String Values - or you could modify the default MS provided ones if you prefer. Check what you 'default' server is (mine shows as 0) as that's the one Windows will use first, and put at the top of the list in the time settings.

If you delete the default MS servers and add your own ensure you have at least 2 servers in the list or when you try & access the 'Time & Date' setting / Internet time setting tab within the clock it will crash and never display the list.

If you want to configre any special ntp options then have a look at this path;

HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\W32Time

Restart the 'Windows Time' service and you should be good to go. There is no reason you couldn't script this either through a .bat or power shell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM