PhoenixXL Posted November 23, 2012 Share Posted November 23, 2012 (edited) This Example checks the CPU usage of the Process expandcollapse popupHotKeySet('{ESC}', '_Exit') Local $sProcName = 'explorer.exe' Local $nPid = ProcessExists($sProcName) ;Check Existence of the Process If Not $nPid Then Exit -1 PollProcessIdleTime($nPid, 5000, 15000) Exit @error Func _CPU_Usage($nPid = 0, $hostname = ".") $objWMIService = ObjGet("winmgmts://" & $hostname & "/root/cimv2") $colProcess = $objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_" & _ "PerfProc_Process Where IDProcess ='" & $nPid & "'") For $objProcess In $colProcess Return Int($objProcess.PercentProcessorTime) Next EndFunc ;==>_CPU_Usage Func _Exit() Exit EndFunc ;==>_Exit ; #FUNCTION# ==================================================================================================================== ; Name ..........: PollProcessIdleTime ; Description ...: Waits or pauses the Execution until the certain process gets Idle for the Specified amount of time ; Syntax ........: PollProcessIdleTime($iPid, $nMilliSecs[, $iTimeout = -1]) ; Parameters ....: $iPid - An integer value. ; $nMilliSecs - A floating point number value. ; $iTimeout - [optional] An integer value. Default is -1. ; ; Return values .: Success - Returns 1 ; Failure - Returns 0 & sets @error to ; | 1 - The Timeout value is equal or less than nMilliSecs ; | 2 - The Process Doesnt Exist or Closed ; | 3 - Timeout Value reached ; ; Author ........: Phoenix XL ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func PollProcessIdleTime($iPid, $nMilliSecs, $iTimeout = -1) If $nMilliSecs >= $iTimeout Then Return SetError(1, 0, 0) Local $gTimer = TimerInit() Local $nTimer While 1 If Not ProcessExists($iPid) Then Return SetError(2, 0, 0) If _CPU_Usage($iPid) Then If $nTimer Then If Round( TimerDiff($nTimer) ) >= $nMilliSecs Then Return 1 ElseIf TimerDiff($gTimer) >= $iTimeout Then Return SetError(3, 0, 0) EndIf $nTimer = 0 EndIf Else If $nTimer = 0 Then $nTimer = TimerInit() EndIf WEnd EndFunc ;==>PollforProcessIdleTime Edited November 23, 2012 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
jmon Posted November 24, 2012 Share Posted November 24, 2012 Here is what you posted (trimmed): $hWnd = ProcessExists("EFrame2.exe") ... ... If WinActive($hWnd) Then ... It seems that you don't understand some basics. Here let me explain the example I posted earlier: what "ProcessExists("EFrame2.exe")" returns is a PID (process ID WIKI). A unique number assigned to this process. When you look for a window, you can either find that window by using it's title and text or using it's handle (hWnd). You cannot use the PID as a Handle, these are totally different things. What "_WinAPI_EnumProcessWindows" returns is an Array of windows belonging to a Process ID (PID). as you can see from the help file of WinAPIEx, the returned array contains Window Handles, so you can use these window handles to check if the window is active or not. So you can see that what you posted earlier don't work. You cannot input directly the PID returned by ProcessExists into WinActive. [center]www.jmontserrat.comFile Sequence UDF - _StringExtractPaths - _StringTrimPattern - GuiCtrlSetOnTop - CalendarUDF[/center] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now