Synchronize Windows Server 2008 time during startup

Status
Not open for further replies.

NewEraCracker

Active Member
1,335
2010
203
10
Click in the clock with the right mouse button and select Adjust date/time, then go to the Internet Time tab, hit Change settings and Update now. If it works, we can proceed.

Create a file with the following contents in C:\sync-clock.php
PHP:
<?php
// Attempt resync
system('w32tm /resync', $return_var);

while( $return_var !== 0 )
{
	// Sleep to avoid excessive looping
	sleep(10);

	// Attempt resync
	system('w32tm /resync', $return_var);
}

// Successful exit
exit(0);
?>

Run Computer Management ( compmgmt.msc ) from Control Panel > System and Security > Administrative Tools.

Go to Task Scheduler Library and Create a Basic Task with When the computer starts as Trigger.

Action will be to Start a Program, Input the path to your php executable (php.exe) in Program/Script.
Add Arguments: -n -f "C:\sync-clock.php"

After task is created, edit its properties:
Change User or Group and type SYSTEM, then confirm
Tick Run with highest privileges
Confirm the changes.
 
Last edited:
2 comments
Status
Not open for further replies.
Back
Top