手机
当前位置:查字典教程网 >脚本专栏 >vbs >VBS中获取系统本次及上次开关机时间的代码(WinXP/win2003/Win7兼容版)
VBS中获取系统本次及上次开关机时间的代码(WinXP/win2003/Win7兼容版)
摘要:复制代码代码如下:If(Lcase(Right(Wscript.FullName,11))="wscript.exe")ThenCreate...

复制代码 代码如下:

If (Lcase(Right(Wscript.FullName,11)) = "wscript.exe") Then

CreateObject("WScript.Shell").Run("%Comspec% /C " &Chr(34)&"mode con cols=100&Cscript.exe //NoLogo "&Chr(34)& Wscript.ScriptFullName &Chr(34)&"&&(Echo 此窗口40秒后自动关闭...&Ping -n 40 127.0.1>nul&Exit)"&Chr(34)),3:Wscript.Quit

Wscript.Quit

End If

Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!.rootcimv2")

Set colLoggedEvents = WMI.ExecQuery("Select * from Win32_NTLogEvent Where Logfile = 'System' And EventCode = '6005' Or EventCode = '6006' Or EventCode = '6008'")

For Each objEvent In colLoggedEvents

Flag = Flag + 1

If Flag = 1 Then

Wscript.Echo "本次开机时间: " & UTCtoNow(objEvent.TimeWritten)

ElseIf (Flag Mod 2) = 0 Then

G = UTCtoNow(objEvent.TimeWritten)

Else

K = UTCtoNow(objEvent.TimeWritten)

Wscript.Echo "前次开机:"&K&" "&vbTab&"对应关机:"&G&" "&vbTab& "运行时长:" &StoHMS(DateDiff("s", K, G))

End If

Next

Function UTCtoNow(nD)

If Not IsNull(nD) Then

Set SWDT = CreateObject("WbemScripting.SWbemDateTime")

SWDT.Value = nD

UTCtoNow = SWDT.GetVarDate(True)

End If

End Function

Function StoHMS(Sec)

H = Int(Sec/3600) :H1 = Sec Mod 3600:M = Int(H1/60) :S = H1 Mod 60

StoHMS = H & "小时" & M & "分钟" & S &"秒"

End Function

【VBS中获取系统本次及上次开关机时间的代码(WinXP/win2003/Win7兼容版)】相关文章:

使用vbs下载文件的代码加强版

用VBS检测U盘插入与弹出事件的代码

用vbs实现按创建日期的顺序列出一个文件夹中的所有文件

校准系统时间的VBS代码

用vbs读取远程计算机上的文本文件的代码

vbs 获取当前目录文件数量的代码(不包括子文件夹中的)

VBS教程:函数-Left 函数

从XML文件中获取信息的vbs代码

VBS获取外网IP地址并发送到指定邮箱的代码

使用脚本调用系统的关机对话框实现代码

精品推荐
分类导航