Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The only generic way to stop a process is to use <a href="http://msdn.microsoft.com/en-us/library/ms686714.aspx" rel="nofollow noreferrer">TerminateProcess</a>. But that's as far from graceful as you can get. To gracefully close a process, you need to tell the process that you'd like it to stop, and then hope it obeys. There is no way to do that in general, though.</p> <p>For a GUI program, the usual way to tell it that you want it to stop running is to close its main window. There's no formal idea of "main window," though. A program can have zero or more windows, and there's no way to know externally which one you're supposed to close in order to make the program stop working.</p> <p>You could use <a href="http://msdn.microsoft.com/en-us/library/ms633497.aspx" rel="nofollow noreferrer">EnumWindows</a> to cycle through all the windows and select the ones that belong to your process. (They'd be the ones for which <a href="http://msdn.microsoft.com/en-us/library/ms633522.aspx" rel="nofollow noreferrer">GetWindowThreadProcessId</a> gives the same process ID that CreateProcess gave you.)</p> <p>Closing a window might not be enough. The program might display a dialog box (prompting for confirmation, or asking to save changes, etc.). You would need to know in advance how to dismiss that dialog box.</p> <p>Non-GUI programs can have similar problems. It might be enough to simulate a Ctrl+C keystroke. It might catch and handle that keystroke differently, though. It might have a menu system that expects you to type "Q" to quit the program.</p> <p>In short, you cannot gracefully close a program unless you know in advance how that program expects to be closed.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload