VBS to obtain the code of the current and last switching time of the system (WinXP / Win2003 / win7 compatible version)

Time:2022-5-14

Copy codeThe code is as follows:


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 this window closes automatically after 40 seconds… & Ping – N 40 127.0.1 > nul & exit)” & Chr (34)), 3: Wscript Quit
Wscript.Quit
End If
Set WMI = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2”)
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 “this boot time:” & utctonow (objeevent. Timewritten)
ElseIf (Flag Mod 2) = 0 Then
G = UTCtoNow(objEvent.TimeWritten)
Else
K = UTCtoNow(objEvent.TimeWritten)
Wscript. Echo “previous power on:” & K & “” & vbtab & “corresponding power off:” & G & “” & vbtab & “run time:” & 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 & “hours” & M & “minutes” & S & “seconds”
End Function

Recommended Today

Openssh upgrade (from openssh_7.4p1 to openssh_8.4p1) [operation Script]

Openssh upgrade (from openssh_7.4p1 to openssh_8.4p1) ##–Status before upgrade [[email protected] ~]# ssh -V OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017 ##–Start upgrade wget -c https://ftp.openssl.org/source/openssl-1.1.1h.tar.gz wget -c https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.4p1.tar.gz yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel yum install -y pam* zlib* mv /usr/bin/openssl /usr/bin/openssl_bak mv /usr/include/openssl /usr/include/openssl_bak tar xfz openssl-1.1.1h.tar.gz cd openssl-1.1.1h […]