Guys
The script below reports the System Uptime. I found parts of this script on the web and with the help of a previous post here, I amended the output to report in days, hours and minutes. Unfortunately, the script appears not to report correctly at certain times of the month (mainly the beginning) and I cannot figure out why? eg. It is reporting my laptop has been up for 118 days when it should report it as 0 days (hours and minutes are correct)
The script is below, please can you offer any advice?
--------------------------------------
"Insert funny comment in here!"
--------------------------------------
The script below reports the System Uptime. I found parts of this script on the web and with the help of a previous post here, I amended the output to report in days, hours and minutes. Unfortunately, the script appears not to report correctly at certain times of the month (mainly the beginning) and I cannot figure out why? eg. It is reporting my laptop has been up for 118 days when it should report it as 0 days (hours and minutes are correct)
The script is below, please can you offer any advice?
Code:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
dtmBootup = objOS.LastBootUpTime
dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
dtmSystemUptime = DateDiff("n", dtmLastBootUpTime, Now)
intDays = dtmSystemUptime \ 1440
intHours = dtmSystemUptime \ 60 - 24 * intDays
intMinutes = dtmSystemUptime Mod 60
msgbox "Device has been up for " & intDays & " days, " & intHours & " hours and " & intMinutes & " minutes"
Next
Function WMIDateStringToDate(dtmBootup)
WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
& " " & Mid (dtmBootup, 9, 2) & ":" & _
Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup,13, 2))
End Function
--------------------------------------
"Insert funny comment in here!"
--------------------------------------