Jump to content
Macro Express Forums
Eg6Xpm18cs

Detect when a running program or task finishes

Recommended Posts

This macro can be used to detect when a running program or task is finished, as an alternative to monitoring controls, pixel colors, log files, mouse cursors, etc. A typical application would be a long-running or unattended task where you want something to happen when the task is finished, e.g. sound an alarm, launch another program, shutdown PC, etc. I suppose it could also be used as an alarm when a task hangs.

 

The macro calls the PsList.exe part of the PsTools Suite

Credit to poster paul for referring me to PsList and providing guidance on how to use it.

 

The macro calls PsList to interrogate CPU activity, extracts CPU run time from PsList and converts it to seconds, then compares it to the CPU time obtained from the previous repeat loop to determine if the process has stopped, i.e. if current and previous CPU times are equal.

 

In the parameters section of the macro, specify the process name to be monitored, and the paths to your PsList.exe and data file. Default delay between CPU interrogations is 30 seconds. Reliability may suffer if short delays are used -- I've noticed that the CPU Time in Windows Task Manager occasionally pauses up to several seconds.... so if the delay is too short, the macro will prematurely signal the end of processing if a long pause occurs.

 

CPU time can be verified by enabling Text Box Display near the end of the macro. A pop-up showing CPU time will appear right after launching the macro, and at every repeat interval thereafter. Compare the CPU time to Task Manager (add CPU Time column in the Processes tab: View / Select Columns).

 

A drawback is that the command window flashes at each CPU interrogation. I don't know how to prevent this, so maybe someone can chime in with a solution.

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×