您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關vbs如何查詢電腦開關機時間,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
核心代碼:
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set colLoggedEvents = objWMIService.ExecQuery _ ("Select * from Win32_NTLogEvent " _ & "Where Logfile = 'System' And EventCode = '6005' Or EventCode = '6006'") For Each objEvent In colLoggedEvents Flag = Flag + 1 If Flag = 1 Then Wscript.Echo "本次開機時間: " & FormatWMIUTC(objEvent.TimeWritten) ElseIf Flag = 2 Then Wscript.Echo "上次關機時間: " & FormatWMIUTC(objEvent.TimeWritten) ElseIf Flag = 3 Then Wscript.Echo "上次開機時間: " & FormatWMIUTC(objEvent.TimeWritten) Exit For End If Next 'FormatUTC Function FormatWMIUTC(WMIDateString) DS = " // :: " FormatWMIUTC = Left(WMIDateString,2) For i = 2 To 7 FormatWMIUTC = FormatWMIUTC & Mid(WMIDateString, i * 2 - 1, 2) & Mid(DS,i,1) Next 'FormatWMIUTC = Mid(WMIDateString, 1, 4) & "年" _ ' & Mid(WMIDateString, 5, 2) & "月" _ ' & Mid(WMIDateString, 7, 2) & "日 " _ ' & Mid (WMIDateString, 9, 2) & ":" _ ' & Mid(WMIDateString, 11, 2) & ":" _ ' & Mid(WMIDateString,13, 2) End Function
將上面的代碼保存為vbs后綴的文件,雙擊運行即可。看到這次的開機時間,上次的開關機時間。
關于“vbs如何查詢電腦開關機時間”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。