Submitted By: Anonymous Submission

Shows the time your computer has been running for since its last reboot.

Visual Basic
Edit|Remove
Set oOS = GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
For Each obj in oOS
  ' if WinXP, use SWbemDateTime for date/time formatting!
  sLastBoot = ConvWbemTime(obj.LastBootUpTime)
  sNow = ConvWbemTime(obj.LocalDateTime)
'wscript.echo snow
'	uptime = DateDiff("s",CDate(sLastBoot),CDate(sNow))
 uptime = DateDiff("s",sLastBoot,sNow)
wscript.echo ((uptime /60) /60 ) & " hours"
Next

Function ConvWbemTime(IntervalFormat)
  Dim sYear, sMonth, sDay, sHour, sMinutes, sSeconds
  sYear = mid(IntervalFormat, 1, 4)
  sMonth = mid(IntervalFormat, 5, 2)
  sDay = mid(IntervalFormat, 7, 2)
  sHour = mid(IntervalFormat, 9, 2)
  sMinutes = mid(IntervalFormat, 11, 2)
  sSeconds = mid(IntervalFormat, 13, 2)

  ' Returning format yyyy-mm-dd hh:mm:ss
  ConvWbemTime = sYear & "-" & sMonth & "-" & sDay & " " _
               & sHour & ":" & sMinutes & ":" & sSeconds
End Function