Reputation: 128
I have several computers in a network that I need to sync timezones with a host. A way that I thought would work would be to export the registration key of the host timezone and import the .Reg on each of the client computers. I am able to do successfully use these commands in command prompt from the host computer to change the registry values
Reg export HKLM\System\CurrentControlSet\Control\TimeZoneInformation\ \\[computer_name]\[SharedFolder]\TimeZone.Reg
then on the remote computer:
Reg import [SharedFolder]\TimeZone.Reg
Yet, when I look at the system clock and it's properties, they have not changed from the original values despite the registry keys are identical between the host and the remote computer. Is there a way to force windows to read the registry for system clock information? Or is there another solution that could help me out here. I'm encapsulating these commands in a c# program so I'm open to alternative programmatic methods.
Thanks!
EDIT:
I don't know why this was marked as a duplicate. This question is directed towards the command line and/or c# solution to changing timezone remotely, not a c++ api solution.
Upvotes: 0
Views: 2661
Reputation: 128
For anybody that is curious, I did use ChristiFati's advice, but encapsulated it with psexec:
psexec \\[remote-computer-name] cmd.exe /c w32tm /config /manualpeerlist:time-nw.nist.gov /syncfromflags:manual /update
psexec \\[remote-computer-name] cmd.exe /c net stop w32time
psexec \\[remote-computer-name] cmd.exe /c net start w32time
The time on the remote computer takes ~ 10 seconds to adjust to the changes you have made, but as long as the timezone is correct, it should display the correct internet time.
EDIT
One line command to do the same thing:
psexec \\[remote-computer-name] cmd.exe /c (w32tm /config /manualpeerlist:time-nw.nist.gov /syncfromflags:manual /update ^& net stop w32time ^& net start w32time)
Upvotes: 0
Reputation: 41106
According to this KB article (it's for XP
but works in W7
) you should let the Windows Time service(W32Time) do this for you:
w32tm /config /syncfromflags:manual /manualpeerlist:peerlist
where peerlist is a space-separated list of Domain Name System (DNS) names or IP addresses.
According to this article W32Time uses UDP 123 port to communicate with other service instances (might require to punch a hole in the firewalls).
Note that changing a HKLM
registry key is not necessarily reflected in real time to the user's settings (there's a greater chance for that to happen modifying HKCU
keys); some changes require re-login or even reboot.
Upvotes: 1