以编程方式查找服务器的正常运行时间

时间:2009-06-11 10:21:39

标签: vb.net windows-server-2000 uptime

有没有人知道以编程方式查找运行Windows 2000的服务器的正常运行时间的方法?我们在用VB.NET编写的机器上运行一个服务,它通过Web服务报告给我们的服务器。

2 个答案:

答案 0 :(得分:2)

另一种方法是使用.NET中的性能计数器,例如

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())

基本上,PerformanceCounter类将返回系统启动的秒数,然后从那里你可以做你想要的。

答案 1 :(得分:0)

如果启用了SNMP,则可以查询以下OID:1.3.6.1.2.1.1.3.0。这将为您提供系统正常运行时间。它被定义为“自上次重新初始化系统的网络管理部分以来的时间(以百分之一秒为单位)。”