Jump to content
Macro Express Forums

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.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...