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.
            Asked
            
        
        
            Active
            
        
            Viewed 3,536 times
        
    2 Answers
2
            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.
        AStopher
        
- 4,207
 - 11
 - 50
 - 75
 
        KnackeredCoder
        
- 384
 - 2
 - 7
 
- 
                    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 Jun 11 '09 at 12:45
 - 
                    Please excuse the formatting, I'm new to this site and am still getting used to getting newlines in comments – Brian Jun 11 '09 at 12:46
 
0
            
            
        If you have SNMP enabled, you can query the following OID: 1.3.6.1.2.1.1.3.0. This will give you the system uptime. It is defined as "The time (in hundredths of a second) since the network management portion of the system was last re-initialized."