Archive for February, 2008

Tuesday, February 5th, 2008

Wie Uptime von einem Computer herausfinden?

Ganz einfach, mit dem folgenden Snippet:

TimeSpan uptimeTs = new TimeSpan();
ManagementClass management = new ManagementClass("Win32_OperatingSystem");
ManagementObjectCollection mngInstance = management.GetInstances();
foreach (ManagementObject mngObject in mngInstance)
{
   DateTime lastBootUp = ManagementDateTimeConverter.ToDateTime(mngObject["LastBootUpTime"].ToString());
   if (lastBootUp != DateTime.MinValue)
   {
      uptimeTs = DateTime.Now - lastBootUp;
   }
}
return uptimeTs;

Erstellt von Dani | Abgelegt in Programmieren | Kommentar schreiben »