一起学习网 一起学习网


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

网络编程 VBS中获取系统本次及上次开关机时间的代码(WinXP/win2003/Win7兼容版) 06-22

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合并一个文件夹里的TXT的实现代码
ConstForReading=1'VBS的这句不能少。dimxint,xinlu,jiuwdimobjfso,objoutputfile,f,fxdimobjTextFile,strtextSetobjFSO=CreateObject("Scripting.FileSystemObject")'创建FSO对象jiuw=inputbox("请输

VBS 硬盘读写统计(分区读写统计)
WinXP,Win7,Win8'原创内容转载、引用代码核心部分请注明出处硬盘读写统计.vbsIf(Lcase(Right(Wscript.FullName,11))="wscript.exe")ThenCreateObject("WScript.Shell").Run("%Comspec%/

VBS实现工作表按指定表头自动分表
在我们实际工作中经常遇到将工作表按某一表头字段分开的情况,我们一般的做法是先按指定表头排序然后分段复制粘贴出去,不但麻烦还很容易搞错


编辑:一起学习网

标签:表头,工作,硬盘,代码,前次