Jump to content
Macro Express Forums

Terminate Process


Greg

Recommended Posts

All

I have a macro that runs fine however have noticed that as part of the macro process it doesn’t appear to terminate a program completely.

 

As a small part of the macro I basically check to see if a program is running and if so terminate it. The program disappears and I can restart at a later time OK.

 

However through the task manager (win2000) it appears that multiple sessions of the program are still running (depends how many times the macro has run). If I were to use the mouse/keyboard (from the macro) and use the file/exit commands the program closes OK and doesn’t appear in task manager.

 

Why would the terminate process command fail to completely close the program? Is this the best command to use? or a funny win2000 thing.

 

Thanks in advance

Greg

Link to comment
Share on other sites

The TerminateProcess command will only work with one instance of a program. If you have multiple instances, then the best way to shut them all down would be to use a scrip like the one I've included below:

 

<IVAR2:01:01:0>
<REP3:08:000001:000002:0001:0:01:1>
<IFOTH:06:1:PROGRAM.EXE>
<TERMPROC:001000:1:F:PROGRAM.EXE>
<ELSE>
<IVAR2:01:01:1>
<ENDIF>
<ENDREP>

 

I've placed each command on a separate line for readability only. If you copy and paste this code, you will get several TextType commands scattered throughout the script. Just remove them and you should be set.

Link to comment
Share on other sites

Thanks

I run a similar way of terminating however it seems that if it does it on a single program it closes the one on the screen but not within the task manager. If at a later time the program is running again and the macro shuts it down, a second program item appears in the task manager (though gone from the screen), so on so on.

Link to comment
Share on other sites

When you close a running program by clicking on a menu entry, button or the X in the upper right-hand corner of the window, certain events are fired off to tell the program that you want it to close. The program may prompt you to save, it may close files or do other clean-up tasks.

 

The Terminate Process macro command does not work the same way. It is more abrupt and should probably be used as a last resort. There are other macro commands that 'request' that a program close.

 

The 'Window Close' command sends a 'Windows Close' message to the specified window. This will normally close the specified window. If the window is the top level window then the entire program should close.

 

The 'Program Shut Down' command sends a 'Windows Quit' message to the program. This should tell the program to gracefully shut down, including all windows associated with the program. The program is given a chance to save and close files and do whatever cleanup is needed.

 

The 'Terminate Process' command tries several things in an attempt to terminate a program. These things can terminate the program without giving an opportunity for a 'graceful shutdown'. The steps are:

 

1. Issue a 'Windows Close' message (like the 'Window Close' macro command').

2. * Wait to see if it succeeds.

3. Issue a 'Windows Quit' message (like the Program Shut Down' macro command).

4. * Wait to see if it succeeds.

5. Issue a Quit message to the thread.

6. * Wait to see if it succeeds.

7. Issue another 'Windows Close' message.

8. * Wait to see if it succeeds.

9. And finally, if all else fails, it sends a 'Windows Terminate Process' message. For this to succeed, you must have elevated privileges. In other words, this may not work for non-administrative users.

 

* Note: The amount of time that the command waits is determined by the 'Timeout' value entered in the 'Terminate Process' command dialog. That is the maximum time that the program waits. If the attempt succeeded in closing the program, then the macro immediately continues.

 

If more than one instance of a program is running, the 'Terminate Process' command will attempt to terminate whichever one Windows finds first.

 

Because the terminate process command does not allow for a graceful shutdown, you may experience certain side affects.

 

In the specific case you describe, you may need to create a repeat loop that includes a Terminate Process command and a Delay command to shut down all instances of the program (as suggested by Chris).

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...