vb.netwindows-server-2000uptime

Finding the Uptime of a server programatically


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.


Solution

  • Another way is to use the performance counters from .NET e.g.

    Dim pc As PerformanceCounter = 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
    Dim ts As TimeSpan = 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.