' Synchronise PC clock with a Network Time Server Option Explicit 'force explicit variable declaration On Error Resume Next 'on error continue at next statement ' Initialize variables Dim WshShell, tCommand, tReturn, tMsg, tServer, CRLF, maxServers, tNum, tLoop CRLF = Chr(13) & Chr(10) maxServers = 4 tNum = 0 tLoop = TRUE Set WshShell = CreateObject( "WScript.Shell" ) ' Set up array of time server names ReDim tServer( maxServers ) tServer(0) = "timeserver01" tServer(1) = "timeserver02" tServer(2) = "timeserver03" tServer(3) = "timeserver04" While tLoop = TRUE tCommand = "NET time \\" + tServer(tNum) + " /set /yes" tReturn = WshShell.Run( tCommand, 7, true ) 'minimise window and wait til finished If tReturn = 0 Then tMsg = "Synchronised time with " & tServer(tNum) & CRLF & "status : " & tReturn WScript.Echo tMsg tLoop = FALSE Else tNum = tNum + 1 If tNum = maxServers Then tMsg = "Failed to synchronise time" WScript.Echo tMsg tLoop = FALSE End If End If Wend