Last BootThis script returns the time at which the computer was started.
Added 283 days ago by Emnico
| Download | |
| Review | ||
| Back | ||
| 74 | Views |
Source code
On Error Resume Next
strComputer = Inputbox ("Enter the name of the machine to be checked:", "Last Boot")
If strComputer = vbNullString then
MsgBox "Either Cancel was selected or you did not enter a machine name.", 16, "Last Boot"
WScript.Quit
End If
Set objWMIService = GetObject("winmgmts:\\" _
& strComputer & "\root\cimv2")
If Err.Number <> 0 Then
MsgBox (strComputer) & " isn't a valid machine name!", 16,"Last Boot"
Wscript.Quit
End If
Err.Clear
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOS in colOperatingSystems
dtmBootup = objOS.LastBootUpTime
Exit For
Next
WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) )
WMIDateStringToTime = CDate(Mid(dtmBootup, 9, 2) & ":" & _
Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup,13, 2))
MsgBox strComputer & vbNewLine & _
"Last Boot Date = " & WMIDateStringToDate & vbNewLine & _
"Last Boot Time = " & WMIDateStringToTime, 64, "Last Boot"
Set colOperatingSystems = nothing
Set objWMIService = nothing
WScript.Quit

