If (Lcase(Right(Wscript.FullName,11)) = "wscript.exe") Then CreateObject("WScript.Shell").Run("%Comspec% /C " Chr(34)"mode con cols=100Cscript.exe //NoLogo "Chr(34) Wscript.ScriptFullName Chr(34)"(Echo 此窗口40秒后自動關(guān)閉...Ping -n 40 127.0.1>nulExit)"Chr(34)),3:Wscript.Quit Wscript.Quit End If Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Set colLoggedEvents = WMI.ExecQuery("Select * from Win32_NTLogEvent Where Logfile = 'System' And EventCode = '6005' Or EventCode = '6006' Or EventCode = '6008'") For Each objEvent In colLoggedEvents Flag = Flag + 1 If Flag = 1 Then Wscript.Echo "本次開機時間: " UTCtoNow(objEvent.TimeWritten) ElseIf (Flag Mod 2) = 0 Then G = UTCtoNow(objEvent.TimeWritten) Else K = UTCtoNow(objEvent.TimeWritten) Wscript.Echo "前次開機:"K" "vbTab"對應(yīng)關(guān)機:"G" "vbTab "運行時長:" StoHMS(DateDiff("s", K, G)) End If Next
Function UTCtoNow(nD) If Not IsNull(nD) Then Set SWDT = CreateObject("WbemScripting.SWbemDateTime") SWDT.Value = nD UTCtoNow = SWDT.GetVarDate(True) End If End Function
Function StoHMS(Sec) H = Int(Sec/3600) :H1 = Sec Mod 3600:M = Int(H1/60) :S = H1 Mod 60 StoHMS = H "小時" M "分鐘" S "秒" End Function