服务器之家

服务器之家 > 正文

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

时间:2020-08-17 11:46     来源/作者:VBS代码网

核心代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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代码

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享
歪歪漫画vip账号共享2020_yy漫画免费账号密码共享 2020-04-07
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
男生常说24816是什么意思?女生说13579是什么意思?
男生常说24816是什么意思?女生说13579是什么意思? 2019-09-17
沙雕群名称大全2019精选 今年最火的微信群名沙雕有创意
沙雕群名称大全2019精选 今年最火的微信群名沙雕有创意 2019-07-07
返回顶部