4月192017
AU3获取内存和CPU占用
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("资源监视", 341, 80, 460, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Label1 = GUICtrlCreateLabel("CPU:", 15, 15, 38, 17)
$Progress1 = GUICtrlCreateProgress(45, 15, 200, 13)
$Label2 = GUICtrlCreateLabel("MEM:", 15, 45, 41, 17)
$Progress2 = GUICtrlCreateProgress(45, 45, 200, 13)
$Label3 = GUICtrlCreateLabel("", 250, 15, 76, 17)
$Label4 = GUICtrlCreateLabel("", 250, 45, 76, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $tIDLETIME, $tKERNELTIME, $tUSERTIME
$tIDLETIME = DllStructCreate('dword;dword')
$tKERNELTIME = DllStructCreate('dword;dword')
$tUSERTIME = DllStructCreate('dword;dword')
Global $S_Idle, $S_Kernel, $S_User
Global $E_Idle, $E_Kernel, $E_User
Global $i_CPU = 0
GetSystemTimes($S_Idle, $S_Kernel, $S_User)
AdlibRegister("CPUInfo", 1000)
AdlibRegister("MemInfo", 1000)
While 1
Sleep(100)
WEnd
Func Form1Close()
Exit
EndFunc
Func MemInfo()
$aInfo = MemGetStats()
If ($aInfo[0] >= 0) And ($aInfo[0] <= 100) Then
GUICtrlSetData($Progress2, $aInfo[0])
GUICtrlSetData($Label4, Round(($aInfo[1]-$aInfo[2])/1024/1024, 2) & "/" & Round($aInfo[1]/1024/1024, 2) & "GB")
EndIf
EndFunc
Func CPUInfo()
GetSystemTimes($E_Idle, $E_Kernel, $E_User)
$i_CPU = CPUCalc()
If ($i_CPU >= 0) And ($i_CPU <= 100) Then
GUICtrlSetData($Progress1, $i_CPU)
GUICtrlSetData($Label3, $i_CPU & "%")
EndIf
GetSystemTimes($S_Idle, $S_Kernel, $S_User)
EndFunc
Func GetSystemTimes(ByRef $sIdle, ByRef $sKernel, ByRef $sUser)
DllCall('kernel32.dll', 'int', 'GetSystemTimes', 'ptr', DllStructGetPtr($tIDLETIME), _
'ptr', DllStructGetPtr($tKERNELTIME), _
'ptr', DllStructGetPtr($tUSERTIME))
$sIdle = DllStructGetData($tIDLETIME, 1)
$sKernel = DllStructGetData($tKERNELTIME, 1)
$sUser = DllStructGetData($tUSERTIME, 1)
EndFunc ;==>GetSystemTimes
Func CPUCalc()
Local $iSystemTime, $i_Total, $i_Idle, $i_Kernel, $i_User
$i_Idle = $E_Idle - $S_Idle
$i_Kernel = $E_Kernel - $S_Kernel
$i_User = $E_User - $S_User
$i_System = ($i_Kernel + $i_User)
$i_Total = Int(($i_System - $i_Idle)/ $i_System * 100)
;ConsoleWrite($i_Total & @CRLF)
Return $i_Total
EndFunc ;==>CPUCalc```
<br />
扫描二维码,在手机上阅读
发表评论
木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!