Drat. w32tm only works if Windows Time service is started which I've always assumed to be default but I guess isn't. Ok then ....The following error occurred: The service has not been started. (0x80070426)
vb.net Code:
' add reference to System.ServiceProcess Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim sc As New ServiceProcess.ServiceController("Windows Time") Dim StartedByProcess As Boolean = False If sc.Status = ServiceProcess.ServiceControllerStatus.Stopped Then sc.Start() sc.WaitForStatus(ServiceProcess.ServiceControllerStatus.Running) StartedByProcess = True End If Dim p As New Process p.StartInfo.FileName = "w32tm" p.StartInfo.Arguments = "/resync " p.StartInfo.CreateNoWindow = True p.StartInfo.UseShellExecute = False p.StartInfo.RedirectStandardOutput = True p.Start() If p.StandardOutput.ReadToEnd.Contains("completed successfully") Then Label1.Text = "Time Synchronised " & Now.ToString Else Label1.Text = "Unable to synchronise time at this time, which may or may not be " & Now.ToString End If If StartedByProcess Then sc.Stop() sc.Dispose() End Sub




Reply With Quote