Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch file that sync your system time and date

I'm trying to write a batch file that checks the system time and date. I would like it to check over the internet. I have this part. But thinking it should do the date part. But it only does the time if the date is correct

@echo off
w32tm /query /peers 
net stop w32time
net start w32time
w32tm /resync /nowait
EOF

I do run the batch file as a administrator. Can someone help me with the date part of this. Thank you for taking the time to read this post. Any info would be a get help. Thank you

like image 910
user2559533 Avatar asked Dec 19 '25 04:12

user2559533


2 Answers

You have the NET TIME statement, but surely you don't have XP or a Lower OS, so that statement is already deprecated. For higher versions, therefore, using W32TM is a time management service that also serves to diagnose system problems.

How to synchronize the time and date from CMD?

  1. Run a console as Administrator.

  2. Start the service: net start w32time

  3. Check its status: w32tm /query /peers

  4. Synchronize the time and date: w32tm /resync /nowait

You can also change the specific time and date of a computer on the network with: net time \\DOMAIN /set

With this, you can now create the Batch script you need.

On the other hand, for more information, I share the source: https://learn.microsoft.com/.../windows.../ff799054(v=ws.11)

like image 71
Antonio Moreno Avatar answered Dec 21 '25 09:12

Antonio Moreno


we push this batch file across networks US and canada via our rmm software

Hope it helps

@echo off
w32tm /query /peers
sc config w32time start= auto
w32tm /config /syncfromflags:manual /manualpeerlist:"0.us.pool.ntp.org,1.us.pool.ntp.org,2.us.pool.ntp.org,3.us.pool.ntp.org"
w32tm /config /reliable:yes
net stop w32time
net start w32time
w32tm /resync /nowait
like image 35
israel galindo Avatar answered Dec 21 '25 08:12

israel galindo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!