I've been searching to find out how to get a remote PC's System.Environment.TickCount. Using this simple code gets the info I want from my local PC but I can't work out how to get the same info for each PC in our domain network. I want to run this from our server.
TimeSpan t = TimeSpan.FromMilliseconds(System.Environment.TickCount);
MessageBox.Show(t.Days.ToString() + "days, " + t.Hours.ToString() + "hrs & " + t.Minutes.ToString() + "mins.");
I've got this code to get all computer names in the network:
public List<String> ListNetworkComputers()
{
List<String> _ComputerNames = new List<String>();
String _ComputerSchema = "Computer";
System.DirectoryServices.DirectoryEntry _WinNTDirectoryEntries = new System.DirectoryServices.DirectoryEntry("WinNT:");
foreach (System.DirectoryServices.DirectoryEntry _AvailDomains in _WinNTDirectoryEntries.Children)
{
foreach (System.DirectoryServices.DirectoryEntry _PCNameEntry in _AvailDomains.Children)
{
if (_PCNameEntry.SchemaClassName.ToLower().Contains(_ComputerSchema.ToLower()))
{
_ComputerNames.Add(_PCNameEntry.Name);
}
}
}
return _ComputerNames;
}
How can I use this info to get the System.Environment.TickCount from each PC? I've tried PsExec.exe but I've really got no clue how to get it to work for me. I tried this but it doesn't work:
var list = ListNetworkComputers();
foreach (var pc in list)
{
string output = "";
using (var process = new System.Diagnostics.Process())
{
process.StartInfo.FileName = @"C:\PsExec.exe";
process.StartInfo.Arguments = @"\\" + pc + " cmd /c echo " + "System.Environment.TickCount";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
output = process.StandardOutput.ReadToEnd();
}
int count = 0;
Int32.TryParse(output, out count);
TimeSpan ts = TimeSpan.FromMilliseconds(count);
MessageBox.Show(pc + ": " + ts.Days.ToString() + "days, " + ts.Hours.ToString() + "hrs & " + ts.Minutes.ToString() + "mins.");
}