45fan.com - 路饭网

搜索: 您的位置主页 > 网络频道 > 阅读资讯:查询电脑开关机时间的vbs代码的详细介绍

查询电脑开关机时间的vbs代码的详细介绍

2016-12-13 18:45:31 来源:www.45fan.com 【

查询电脑开关机时间的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代码的详细介绍


本文地址:http://www.45fan.com/a/question/86028.html
Tags: 开关 电脑 查询
编辑:路饭网
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部