设为首页 - 加入收藏
广告 1000x90
您的当前位置:主页 > 网站运营 > 正文

查询电脑开关机时间的vbs代码

来源:网络分享 编辑:引流技巧 时间:2026-01-26

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

相关推荐:

栏目分类

微商引流技巧网 www.yinliujiqiao.com 联系QQ:1716014443 邮箱:1716014443@qq.com

Copyright © 2019-2024 强大传媒 吉ICP备19000289号-9 网站地图 rss地图

Top