Uptime

  • This topic has 3 replies, 3 voices, and was last updated 11 years ago by doug.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #8593
    pausen
    Participant

    Hi,

    you can already get the last boottime, but i would also be great if you can get the calculated uptime in min,hours,days and/or years.

    Regards

    #9503
    doug
    Moderator

    We’ll consider this for a future build.

    Thanks,

    Doug

    #9519
    JasonW
    Participant

    If you are already getting boottime this should be simple. Assuming you are using WMI, you also want to get the localtime on the host and not what you are scanning from so the uptime is accurate. This is what I wrote on an internal program I use.

    Public Function GetUptime() As String

    Try

    Dim searcher As New ManagementObjectSearcher(“\” & hostname & “rootCIMV2”, “SELECT * FROM Win32_OperatingSystem”)

    Dim Bootime As DateTime

    Dim localtime As DateTime

    For Each queryObj As ManagementObject In searcher.Get()

    Bootime = System.Management.ManagementDateTimeConverter.ToDateTime(queryObj(“LastBootUpTime”))

    localtime = System.Management.ManagementDateTimeConverter.ToDateTime(queryObj(“LocalDateTime”))

    Next

    Dim TS As TimeSpan = localtime – Bootime

    ‘Nice Clean output

    Dim time As String = TS.Days.ToString & ” Day(s) ” & TS.Hours & ” Hour(s) ” & TS.Minutes.ToString & ” Minute(s) ” & TS.Seconds.ToString & ” Seconds”

    Return time

    Catch ex As Exception

    Return “Error: ” & ex.Message.Split(“(“)(0)

    End Try

    End Function

    #9520
    doug
    Moderator

    Thanks, Jason!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.