qwert Posted December 30, 2007 Share Posted December 30, 2007 I use an au3 script to adjust the window of a database application after it has initialized. Since that initialization includes the application's own window size/position settings, I have to wait until it is fully initialized before issuing my window commands. I've tried using a WinWaitActive step -- even followed by a 2 second pause -- to determine when to initiate the Set Style commands. The problem is that the application takes a different amount of time to initialize, mostly depending on the current runtime environment of the PC (e.g., how many applications are already running). Is there another way to test that an application is "ready" -- or "idle"? If not, what is a recommended way to pass a signal from a startup script inside the database application? Any suggestions will be appreciated. Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 30, 2007 Share Posted December 30, 2007 (edited) You can use _ProcessListProperties() to check when that PID goes idle. Edited July 2, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
qwert Posted December 31, 2007 Author Share Posted December 31, 2007 Thanks for the response. Your function looks like a great foundation for building task management capability into a script, but it's somewhat beyond my level of au3 capability at this point. I've tried to follow the code to determine a way to check for status = idle, but I can't see it. Is there a single WMI call that can be fashioned to only return the status for a single PID? Or, since my need is rather simple, would it be better to have the application launch a "drone task" when initialization is complete -- and then have my main script use a ProcessWait to pause until it runs? (BTW, my main script is the one that starts the database application.) Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 31, 2007 Share Posted December 31, 2007 Thanks for the response. Your function looks like a great foundation for building task management capability into a script, but it's somewhat beyond my level of au3 capability at this point. I've tried to follow the code to determine a way to check for status = idle, but I can't see it. Is there a single WMI call that can be fashioned to only return the status for a single PID? Or, since my need is rather simple, would it be better to have the application launch a "drone task" when initialization is complete -- and then have my main script use a ProcessWait to pause until it runs? (BTW, my main script is the one that starts the database application.) You don't have to figure out the internals of the function to use it. The function _ProcessListProperties() returns a 2D array listing properties of matching processes (figure out how another day). If you specify the PID or name of the process you are interested in, you get only results for that process, but still in a 2D array. The CPU usage would be in the returned array at [1][6]. Assuming CPU usage of 0 for that process over 3 consecutive seconds is a sufficient test of "idleness", the test would look like this: $sDir = "C:\Program Files\Your\Program\Here" $sEXE = $sDir & "\Executable.exe" ; Run your program $PID = Run($sEXE, $sDir) ; Loop untill CPU usage is 0 for three consecutive seconds $iCnt = 0 Do Sleep(1000) $avProps = _ProcessListProperties($PID) If $avProps[0][0] <> 0 Then If $avProps[1][6] = 0 Then $iCnt += 1 Else $iCnt = 0 EndIf Else MsgBox(16, "Error", "Error! PID " & $PID & " doesn't exist.") Exit EndIf Until $iCnt = 3 MsgBox(64, "Idle", "PID " & $PID & " has been idle for at least 3 consecutive seconds.") You need to include the function declaration from _ProcessListProperties(), just copy/paste that into your script. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
qwert Posted December 31, 2007 Author Share Posted December 31, 2007 The example you provided makes everything clear (re: monitoring CPU usage). I can see that using the entire function makes sense in this instance, since it is somewhat involved. Usually, when I only need to make one call (ever) to a function, I look for a way to fashion a script step or two to perform only the part of the function that I need -- which helps keep my own script simple and understandable. That's what led me to the question in my response. Anyway, thanks very much for your help on this. Link to comment Share on other sites More sharing options...
Greenhorn Posted January 1, 2008 Share Posted January 1, 2008 (edited) Or maybe you can retrieve a text in the Statusbar of the window that shows 'ready' or something like that !? Greetz Greenhorn Edited January 1, 2008 by Greenhorn Link to comment Share on other sites More sharing options...
herewasplato Posted January 1, 2008 Share Posted January 1, 2008 ...and then there are the pixel functions - perhaps PixelCheckSum. [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Redrodan Posted July 2, 2008 Share Posted July 2, 2008 You don't have to figure out the internals of the function to use it. The function _ProcessListProperties() returns a 2D array listing properties of matching processes (figure out how another day). If you specify the PID or name of the process you are interested in, you get only results for that process, but still in a 2D array. The CPU usage would be in the returned array at [1][6]. Assuming CPU usage of 0 for that process over 3 consecutive seconds is a sufficient test of "idleness", the test would look like this: $sDir = "C:\Program Files\Your\Program\Here" $sEXE = $sDir & "\Executable.exe" ; Run your program $PID = Run($sEXE, $sDir) ; Loop untill CPU usage is 0 for three consecutive seconds $iCnt = 0 Do Sleep(1000) $avProps = _ProcessListProperties($PID) If $avProps[0][0] <> 0 Then If $avProps[1][6] = 0 Then $iCnt += 1 Else $iCnt = 0 EndIf Else MsgBox(16, "Error", "Error! PID " & $PID & " doesn't exist.") Exit EndIf Until $iCnt = 3 MsgBox(64, "Idle", "PID " & $PID & " has been idle for at least 3 consecutive seconds.") You need to include the function declaration from _ProcessListProperties(), just copy/paste that into your script. I hate to reply to an old post but this reference is exactly what I'm looking for. I've tried this sample code but everytime I try it, I get a window with the entire list of processes. I used Notepad.exe is my Executable.exe and I'm also getting the follow errors: C:\Program Files\AutoIt3\Include\_ProcessListProperties.au3 (63) : ==> The requested action with this object has failed.: If $oProc.GetOwner($sUserName, $sUserDomain) = 0 Then $avProcs[$n][3] = $sUserDomain & "\" & $sUserName If $oProc.GetOwner($sUserName, $sUserDomain) ^ ERROR Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 2, 2008 Share Posted July 2, 2008 I hate to reply to an old post but this reference is exactly what I'm looking for. I've tried this sample code but everytime I try it, I get a window with the entire list of processes. I used Notepad.exe is my Executable.exe and I'm also getting the follow errors: C:\Program Files\AutoIt3\Include\_ProcessListProperties.au3 (63) : ==> The requested action with this object has failed.: If $oProc.GetOwner($sUserName, $sUserDomain) = 0 Then $avProcs[$n][3] = $sUserDomain & "\" & $sUserName If $oProc.GetOwner($sUserName, $sUserDomain) ^ ERROR Actually, you found a serious bug in _ProcessListProperties(). I had removed ProcessList() from inside the function, and the way I did it broke the ability to find processes by PID or name. The patched version is v2.0.2 dated 07/02/2008. The function was moved to its own topic in Example Scripts. Get _ProcessListProperties() here from now on. Thanks for reporting your issue. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Redrodan Posted July 2, 2008 Share Posted July 2, 2008 Actually, you found a serious bug in _ProcessListProperties(). I had removed ProcessList() from inside the function, and the way I did it broke the ability to find processes by PID or name. The patched version is v2.0.2 dated 07/02/2008. The function was moved to its own topic in Example Scripts. Get _ProcessListProperties() here from now on. Thanks for reporting your issue. The error is gone but the window titled "%avRet" is still coming up with the entire list of processes. After I close that window I get my MsgBox with the CPU usage. Is there something I'm missing to suppress that dialog with the entire list? CODE#include <_ProcessListProperties.au3> $stats = _ProcessListProperties("application.exe") MsgBox(0, "App CPU Usage usage",Number($stats[1][6])) Thanks for your help Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 3, 2008 Share Posted July 3, 2008 (edited) The error is gone but the window titled "%avRet" is still coming up with the entire list of processes. After I close that window I get my MsgBox with the CPU usage. Is there something I'm missing to suppress that dialog with the entire list? CODE#include <_ProcessListProperties.au3> $stats = _ProcessListProperties("application.exe") MsgBox(0, "App CPU Usage usage",Number($stats[1][6])) Thanks for your help I strongly suspect you copied the little demo script into your "_ProcessListProperties.au3" UDF, and not just the function... ...I'm just glad I've never made such a silly mistake! Edited July 3, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Redrodan Posted July 3, 2008 Share Posted July 3, 2008 I strongly suspect you copied the little demo script into your "_ProcessListProperties.au3" UDF, and not just the function......I'm just glad I've never made such a silly mistake! muttleyDoh! Thanks Link to comment Share on other sites More sharing options...
liteswap Posted December 15, 2008 Share Posted December 15, 2008 Doh! ThanksThis is just what I've been looking for too - just stumbled on it - thanks for PSaltyDS. However, I'm getting this error: C:\BATCH\AutoIt scripts\process_list_properties.au3 (129) : ==> The requested action with this object has failed.:$colProcs = $oRefresher.AddEnum($oWMI, "Win32_PerfFormattedData_PerfProc_Process" ).objectSet$colProcs = $oRefresher.AddEnum($oWMI, "Win32_PerfFormattedData_PerfProc_Process" )^ ERRORI'm just running it using the demo calls under XP with admin privs. Thoughts on what might be causing it would be gladly received. Link to comment Share on other sites More sharing options...
PsaltyDS Posted December 15, 2008 Share Posted December 15, 2008 This is just what I've been looking for too - just stumbled on it - thanks for PSaltyDS. However, I'm getting this error: C:\BATCH\AutoIt scripts\process_list_properties.au3 (129) : ==> The requested action with this object has failed.:$colProcs = $oRefresher.AddEnum($oWMI, "Win32_PerfFormattedData_PerfProc_Process" ).objectSet$colProcs = $oRefresher.AddEnum($oWMI, "Win32_PerfFormattedData_PerfProc_Process" )^ ERRORI'm just running it using the demo calls under XP with admin privs. Thoughts on what might be causing it would be gladly received.Just running the demo in the first post of the example topic? That's odd.Add a COM Error handler (in the help file under "OBJ/COM Reference") to see if more useful info turns up. Actually, there should always be one in any script that uses COM interfaces anyway, so I added it to the demo in the example scripts topic, too. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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