代码之家  ›  专栏  ›  技术社区  ›  Brian

通过程序查找服务器的正常运行时间

  •  2
  • Brian  · 技术社区  · 17 年前

    有人知道如何通过程序查找运行Windows2000的服务器的正常运行时间吗?我们有一个在用vb.net编写的机器上运行的服务,它通过一个WebService向我们的服务器报告。

    2 回复  |  直到 17 年前
        1
  •  2
  •   AStopher    11 年前

    另一种方法是使用.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类将返回系统运行的秒数,从那里开始您可以做您想要做的事情。

        2
  •  0
  •       17 年前

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