Does anyone know of a way to programatically find the uptime of a server running Windows 2000? We have a service running on the machine written in VB.NET, that reports back to our server via a webservice.
+1
A:
Another way is to use the performance counters from .NET (sorry, this is in C# but you can easily convert over to VB) e.g.
var pc = new PerformanceCounter("System", "System Up Time");
pc.NextValue(); // This returns zero for a reason I don't know
// This call to NextValue gets the correct value
TimeSpan ts = TimeSpan.FromSeconds(pc.NextValue());
So basically, the PerformanceCounter class will return the number of seconds the system has been up and from there you can do what you want.
KnackeredCoder
2009-06-11 10:55:10
Thanks, this worked for me. As a reference for other people here is the converted VB code I used:Dim uptimeTs As New TimeSpan()Dim pc As New PerformanceCounter("System", "System Up Time") pc.NextValue() uptimeTs = TimeSpan.FromSeconds(pc.NextValue())
Brian
2009-06-11 12:45:26
Please excuse the formatting, I'm new to this site and am still getting used to getting newlines in comments
Brian
2009-06-11 12:46:07