- 工信部备案号 滇ICP备05000110号-1
- 滇公安备案 滇53010302000111
- 增值电信业务经营许可证 B1.B2-20181647、滇B1.B2-20190004
- 云南互联网协会理事单位
- 安全联盟认证网站身份V标记
- 域名注册服务机构许可:滇D3-20230001
- 代理域名注册服务机构:新网数码
这篇文章主要介绍了查询电脑开关机时间的vbs代码,需要的朋友可以参考下
核心代码:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" _
& strComputer & " ootcimv2")
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后缀的文件,双击运行即可。看到这次?开机时间,上次的开关机时间。
售前咨询
售后咨询
备案咨询
二维码
TOP