Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
'==========================================================================
'
' NAME: ReportSystemUptime.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE : 06/10/2007
' COPYRIGHT (c) 2007 All Rights Reserved
'
' COMMENT:
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED To
' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
' PARTICULAR PURPOSE.
'
' IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS
' BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
' DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
' WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
' ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
' OF THIS CODE OR INFORMATION.
'
'==========================================================================
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
lastBootTime = dConvertWMItoVBSDate(objItem.LastBootUpTime)
MsgBox "LastBootUpTime: " & lastBootTime & vbCrLf & _
"System Uptime: " & datediffToWords(lastBootTime, Now)
Next
Private Function dConvertWMItoVBSDate(sDate)
Dim sMonth, sDay, sYear, sHour, sMinutes, sSeconds
sMonth = Mid(sDate,5,2)
sDay = Mid(sDate,7,2)
sYear = Mid(sDate,1,4)
sHour = Mid(sDate,9,2)
sMinutes = Mid(sDate,11,2)
sSeconds = Mid(sDate,13,2)
dConvertWMItoVBSDate = DateSerial (sYear, sMonth, sDay) + TimeSerial (sHour, sMinutes, sSeconds)
End Function
Function datediffToWords(d1, d2)
report = ""
'Start with total number of days
days = DateDiff("d",d1,d2)
'Convert days to years and grab remaining days
If days > 365 Then
years = days\365
days = days Mod (365*years)-1
report = years & " Year(s), "
Else
years = 0
End If
'Thank you PHV for help simplifying the month calculation
'Compute the number of months
months = Int(DateDiff("m",d1,d2))+(day(d2)<day(d1))
'remove years from the total months
months = months Mod 12
If months > 0 Then
report = report & Months & " Month(s), "
End If
'now find the days
newStart = Month(d1) & "/" & Day(d1) & "/" & Year(d1) + years
If Month(d1) <> 12 Then
fullmonthStart = Month(d1) + 1 & "/1/" & Year(d1) + years
Else
fullmonthStart = "1/1/" & Year(d1) + years +1
End If
If Day(d1) =< Day(d2) Then
days = Day(d2) - Day(d1)
Else
days = DateDiff("d", newStart, fullmonthStart) + Day(d2) -1
End If
If days > 0 Then
report = report & days & " day(s), "
End If
'now we will deal with the time left over
'begin by getting total seconds between dates and divide out the days
'grab the remaining seconds with the mod operator
Seconds = abs(datediff("S", d1, d2))
if Seconds <= 0 then
report = "0 seconds."
else
Seconds = Seconds mod (24*60*60)
'divide by 3600 to get hours
If Seconds >= 3600 then
report = report & _
Seconds\(3600) & " hours(s), "
end If
'use mod to get remaining seconds and divide to get minutes
Seconds = Seconds mod (60*60)
if Seconds >= 60 then
report = report & _
Seconds\(60) & " minutes(s), "
end If
'use mod to get remaining seconds
seconds = Seconds Mod (60)
report = report & seconds & " second(s)"
end if
datediffToWords = report
End Function
wmic OS Where (Primary="TRUE") Get LastBootUpTime
To me, something is easy when it's built in and quick.
Again, nothing wrong with the script, but I would not consider it easier.
(I know that no offense was intended and I am not reading it that way).