顯示系統執行時間

2022-02-01 11:50:40 字數 2710 閱讀 4894

strcomputer ="."

set dtmconverteddate = createobject("

wbemscripting.swbemdatetime")

set objwmiservice = getobject("

winmgmts:"_

& "!\\" & strcomputer & "

\root\cimv2")

set coloperatingsystems =objwmiservice.execquery _

("select * from win32_operatingsystem")

foreach objos in

coloperatingsystems

dtmconverteddate.value =objos.lastbootuptime

dtmlastbootuptime =dtmconverteddate.getvardate

dtmsystemuptime = stohms(datediff("s"

, dtmlastbootuptime, now))

wscript.echo dtmsystemuptime

next

function

stohms(sec)

h = int(sec/3600) :h1 = sec mod

3600 :m = int(h1/60) :s = h1 mod

60stohms = h & "

小時" & m & "

分鐘" & s &"秒"

end function

該例還可簡化為for each objos in getobject("winmgmts:").instancesof ("win32_operatingsystem")  next

再來個ahk版的

for objos in comobjget("winmgmts:\\").instancesof("win32_operatingsystem")

再來個呼叫win32_ntlogevent查尋最近開關機時間

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

endif

set wmi = getobject("

winmgmts:!\\.\root\cimv2")

set colloggedevents = wmi.execquery("

select * from win32_ntlogevent where logfile = 'system' and eventcode = '6005' or eventcode = '6006' or eventcode = '6008'")

foreach 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))

endif

next

function

utctonow(nd)

ifnot isnull(nd) then

set swdt = createobject("

wbemscripting.swbemdatetime")

swdt.value =nd

utctonow = swdt.getvardate(true

)

endif

end function

function

stohms(sec)

h = int(sec/3600) :h1 = sec mod

3600:m = int(h1/60) :s = h1 mod

60stohms = h & "

小時" & m & "

分鐘" & s &"秒"

end function

VC 獲取程式執行時間和系統執行時間

cstring str,str1 獲取程式執行時間 long t1 gettickcount 程式段開始前取得系統執行時間 ms sleep 500 afxmessagebox do something.long t2 gettickcount 程式段結束後取得系統執行時間 ms str.forma...

mysql顯示SQL語句執行時間

檢視 mysql 語法 詳細執行時間 與 cpu 記憶體使用量 mysql query profiler mysql 的 sql 語法調整主要都是使用 explain 但是這個並沒辦法知道詳細的 ram memory cpu 等使用量.於 mysql 5.0.37 以上開始支援 mysql quer...

mysql顯示SQL語句執行時間

檢視 mysql 語法 詳細執行時間 與 cpu 記憶體使用量 mysql query profiler mysql 的 sql 語法調整主要都是使用 explain 但是這個並沒辦法知道詳細的 ram memory cpu 等使用量.於 mysql 5.0.37 以上開始支援 mysql quer...