这篇文章将为大家详细讲解有关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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。