Emnico in Swindon and its partners
in the UK and Europe provide:

» IT Support Services and Products
» Bespoke Software Development


Contact our Swindon office on:
+44 (0)1793 614 700
to discuss your IT needs.


CLOSE IT
Emnico Logo
Your Virtual Technology Team
Delivering Peak Performance
Category: Type: Order:
Search For:  
Home > Library > Last Boot

Last Boot

This script returns the time at which the computer was started.
Added 283 days ago by Emnico
Download
Review
Back
74Views
This script has been successfully tested by Emnico and is verified to be working.

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


| Privacy policy | Environmental policy | Site map |