Is there any class available to get a remote PC\'s date time in .net? In order to do it, I can use a computer name or time zone. For each case, are there different ways to g
Since WMI code would be very slow, you can use the below code to get faster results
string machineName = "vista-pc";
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.FileName = "net";
proc.StartInfo.Arguments = @"time \\" + machineName;
proc.Start();
proc.WaitForExit();
List results = new List();
while (!proc.StandardOutput.EndOfStream)
{
string currentline = proc.StandardOutput.ReadLine();
if (!string.IsNullOrEmpty(currentline))
{
results.Add(currentline);
}
}
string currentTime = string.Empty;
if (results.Count > 0 && results[0].ToLower().StartsWith(@"current time at \\" + machineName.ToLower() + " is "))
{
currentTime = results[0].Substring((@"current time at \\" + machineName.ToLower() + " is ").Length);
Console.WriteLine(DateTime.Parse(currentTime));
Console.ReadLine();
}