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

Vb.net 以编程方式查找服务器的正常运行时间,vb.net,windows-server-2000,uptime,Vb.net,Windows Server 2000,Uptime,有人知道一种通过编程查找运行Windows 2000的服务器的正常运行时间的方法吗?我们有一个在VB.NET编写的机器上运行的服务,它通过Web服务向我们的服务器报告。另一种方法是使用.NET中的性能计数器,例如 Dim pc As PerformanceCounter = New PerformanceCounter("System", "System Up Time") pc.NextValue() ' This returns zero for a reason I don't know

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

另一种方法是使用.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类将返回系统启动的秒数,从那里您可以执行您想要的操作。

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

谢谢,这对我很有用。作为其他人的参考,这里是我使用的转换后的VB代码:Dim uptimeTs As New TimeSpan()Dim pc As New PerformanceCounter(“系统”、“系统启动时间”)pc.NextValue()uptimeTs=TimeSpan.FromSeconds(pc.NextValue())请原谅格式设置,我是这个网站的新手,仍然习惯于在评论中使用换行符