Calling TaskKill on a responsive process. Does it forcefully terminate it as well?

2

I know that one can use Windows taskkill utility to "kill" a non-responsive process. But what happens if I call it on a process that is running and has no issues -- will taskkill try to quit it normally first?

PS. The reason I'm asking is because I want to use taskkill from a script to close one program, but I won't use it if it "forcefully" terminates the program's process without first letting it quit "gracefully."

MikeF

Posted 2014-10-30T01:01:44.583

Reputation: 518

Answers

2

By default, the taskkill utility will send a WM_CLOSE signal to the process. This is the same signal as is sent when you click the red x in the titlebar.

A well written app will listen for this signal, and initiate clean-up and close.

If it is stuck, it won't be able to do this, and so is deemed unresponsive. Taskkill willl wait for normal shutdown and then prompt the user for an unconditional shutdown.

You can use the /f parameter to go straight to unconditional shutdown.

So in answer to your question, if you want to not-forcefully close an app, use taskkill without the /f parameter.

Paul

Posted 2014-10-30T01:01:44.583

Reputation: 52 173

1Thanks. How do you know that it "sends a WM_CLOSE signal to the process"? – MikeF – 2014-10-30T03:09:36.827

1@MikeF I don't "know" it, I accept what others have found to be probably true. You can do the same, or you could find an app that watches the message pump, do a taskkill and see if WM_CLOSE appears in the queue. To indirectly confirm, open notepad, write stuff in it, then taskkill notepad. You should get a confirmation to close or save from notepad, which means it recieved a close signal rather than being terminated. Then do the same with taskill /f to see the difference. – Paul – 2014-10-30T03:18:25.220