VBS中獲取系統(tǒng)本次及上次開關(guān)機(jī)時(shí)間的代碼(WinXP/win2003/Win7兼容版)
更新時(shí)間:2013年01月14日 16:05:25 作者:
獲取系統(tǒng)本次及上次開關(guān)機(jī)時(shí)間的vbs代碼,經(jīng)測(cè)試兼容WinXP/win2003/Win7系統(tǒng),喜歡的朋友可以收藏下
復(fù)制代碼 代碼如下:
If (Lcase(Right(Wscript.FullName,11)) = "wscript.exe") Then
CreateObject("WScript.Shell").Run("%Comspec% /C " &Chr(34)&"mode con cols=100&Cscript.exe //NoLogo "&Chr(34)& Wscript.ScriptFullName &Chr(34)&"&&(Echo 此窗口40秒后自動(dòng)關(guān)閉...&Ping -n 40 127.0.1>nul&Exit)"&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 "本次開機(jī)時(shí)間: " & UTCtoNow(objEvent.TimeWritten)
ElseIf (Flag Mod 2) = 0 Then
G = UTCtoNow(objEvent.TimeWritten)
Else
K = UTCtoNow(objEvent.TimeWritten)
Wscript.Echo "前次開機(jī):"&K&" "&vbTab&"對(duì)應(yīng)關(guān)機(jī):"&G&" "&vbTab& "運(yùn)行時(shí)長(zhǎng):" &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 & "小時(shí)" & M & "分鐘" & S &"秒"
End Function
相關(guān)文章
使用批處理文件異地備份數(shù)據(jù)庫(最近幾天的數(shù)據(jù))
數(shù)據(jù)庫異地備份對(duì)一個(gè)網(wǎng)站來說是非常必要的,這里談一下使用批處理文件對(duì)數(shù)據(jù)庫異地本份的過程2006-06-06VBS教程:函數(shù)-DatePart 函數(shù)
VBS教程:函數(shù)-DatePart 函數(shù)...2006-11-11VBS 自動(dòng)登錄論壇的實(shí)現(xiàn)代碼
這篇文章主要介紹了如果通過vbs實(shí)現(xiàn)論壇自動(dòng)登錄的實(shí)現(xiàn)方法,其實(shí)主要利用了vbs操作網(wǎng)頁表單的自動(dòng)填寫實(shí)現(xiàn),喜歡的朋友可以試試2013-07-07Dynamic Activity Window動(dòng)態(tài)活動(dòng)窗口vbs
Dynamic Activity Window動(dòng)態(tài)活動(dòng)窗口2008-12-12