Politely closing an app
-
I have a script that needs to shut down a running application. (e.g. I want to stop a process from the command line.) I'm currently using pskill[^] from Sysinternals, but that literally kills the application - I want to give it a chance to shut down orderly. I'm not opposed to writing an app to find the window and send a WM_QUIT, but surely there's a non-coding way. In Unix, I would do either "pkill appname" or "pkill -HUP appname."
-
I have a script that needs to shut down a running application. (e.g. I want to stop a process from the command line.) I'm currently using pskill[^] from Sysinternals, but that literally kills the application - I want to give it a chance to shut down orderly. I'm not opposed to writing an app to find the window and send a WM_QUIT, but surely there's a non-coding way. In Unix, I would do either "pkill appname" or "pkill -HUP appname."
krism42 wrote:
but surely there's a non-coding way
Windows is a GUI-centric OS. The polite way to do it is via the mouse, or keyboard shortcuts. I doubt very much that there are command line utilities that comes with the OS, that can do what you want. sysinternals.com says: "Windows NT/2000 does not come with a command-line 'kill' utility. You can get one in the Windows NT or Win2K Resource Kit". Don't know if it sends WM_QUIT or not.
krism42 wrote:
In Unix, I would do either "pkill appname" or "pkill -HUP appname."
Then you would get something like pkill: not found :rolleyes: (It's kill)
-
I have a script that needs to shut down a running application. (e.g. I want to stop a process from the command line.) I'm currently using pskill[^] from Sysinternals, but that literally kills the application - I want to give it a chance to shut down orderly. I'm not opposed to writing an app to find the window and send a WM_QUIT, but surely there's a non-coding way. In Unix, I would do either "pkill appname" or "pkill -HUP appname."
-
krism42 wrote:
but surely there's a non-coding way
Windows is a GUI-centric OS. The polite way to do it is via the mouse, or keyboard shortcuts. I doubt very much that there are command line utilities that comes with the OS, that can do what you want. sysinternals.com says: "Windows NT/2000 does not come with a command-line 'kill' utility. You can get one in the Windows NT or Win2K Resource Kit". Don't know if it sends WM_QUIT or not.
krism42 wrote:
In Unix, I would do either "pkill appname" or "pkill -HUP appname."
Then you would get something like pkill: not found :rolleyes: (It's kill)
-
taskkill on XP. But it does not do a polite shutdown. As for pkill/kill, 'pkill' kills by process name, 'kill' kills by process ID. I have not seen any variant of unix in the last ten years that did not include pkill.
pkill - never heard of it. But then again, I've always been a friend of the GNU utilities, which has killall. :) I have now successfully demonstrated that GNU makes you ignorant! :-D
-
I have a script that needs to shut down a running application. (e.g. I want to stop a process from the command line.) I'm currently using pskill[^] from Sysinternals, but that literally kills the application - I want to give it a chance to shut down orderly. I'm not opposed to writing an app to find the window and send a WM_QUIT, but surely there's a non-coding way. In Unix, I would do either "pkill appname" or "pkill -HUP appname."
Is Task Manager :: End task polite enough for you '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd
-
I have a script that needs to shut down a running application. (e.g. I want to stop a process from the command line.) I'm currently using pskill[^] from Sysinternals, but that literally kills the application - I want to give it a chance to shut down orderly. I'm not opposed to writing an app to find the window and send a WM_QUIT, but surely there's a non-coding way. In Unix, I would do either "pkill appname" or "pkill -HUP appname."
-
Is Task Manager :: End task polite enough for you '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd
-
Just do a SendWindowMessage(FindWindow("window text", or class), WM_CLOSE, 0, 0); Write a little command line program to do that and you have your solution. Nunc est bibendum
Ah, and that would work except that the application interprets "WM_CLOSE" as "minimize to system tray." I really dont have much of a problem killing the app with pskill or taskkill - but then it leaves that stinking tray icon hanging around. I have to mouseover it to make it go away; restarting explorer does the trick, too. I really don't want to restart explorer however, as it loses any toolbar/etc changes you may have made since the last boot. I did try to do a FindWindow() for the notification area, but it always returns NULL - irregardless of what combintation I try...
-
pkill - never heard of it. But then again, I've always been a friend of the GNU utilities, which has killall. :) I have now successfully demonstrated that GNU makes you ignorant! :-D
-
taskkill on XP. But it does not do a polite shutdown. As for pkill/kill, 'pkill' kills by process name, 'kill' kills by process ID. I have not seen any variant of unix in the last ten years that did not include pkill.
By the way, which message pump is to receive WM_QUIT in a multi message pump application? The MSDN docs states that WM_QUIT can't be posted using PostMessage, but PostQuitMessage. This makes me think that you can't just post a WM_QUIT message from another process. Sounds like you have to make the process call PostQuitMessage(), unless you can inject code into the target process. Beats me how to do that. Sounds like you need a 8th dan black belt or higher in the art of voodoo hacking. :) (There's probably a reason why sysinternals.com kill command utility does not provide a WM_QUIT option) There may be a way to do it anyhow. If I recall correctly, by pressing the kill button ([X]-button), the message WM_CLOSE is sent to that window. If the main window is closed, the application usually terminates, so that's a good thing. The one problem with that is that WM_CLOSE may have a hook which asks the user to save changes, or whatever.
-
Ah, and that would work except that the application interprets "WM_CLOSE" as "minimize to system tray." I really dont have much of a problem killing the app with pskill or taskkill - but then it leaves that stinking tray icon hanging around. I have to mouseover it to make it go away; restarting explorer does the trick, too. I really don't want to restart explorer however, as it loses any toolbar/etc changes you may have made since the last boot. I did try to do a FindWindow() for the notification area, but it always returns NULL - irregardless of what combintation I try...
-
By the way, which message pump is to receive WM_QUIT in a multi message pump application? The MSDN docs states that WM_QUIT can't be posted using PostMessage, but PostQuitMessage. This makes me think that you can't just post a WM_QUIT message from another process. Sounds like you have to make the process call PostQuitMessage(), unless you can inject code into the target process. Beats me how to do that. Sounds like you need a 8th dan black belt or higher in the art of voodoo hacking. :) (There's probably a reason why sysinternals.com kill command utility does not provide a WM_QUIT option) There may be a way to do it anyhow. If I recall correctly, by pressing the kill button ([X]-button), the message WM_CLOSE is sent to that window. If the main window is closed, the application usually terminates, so that's a good thing. The one problem with that is that WM_CLOSE may have a hook which asks the user to save changes, or whatever.
Oops.. Where I said "WM_QUIT," interpret that to mean "WM_CLOSE". :) In a later post I mentioned that WM_CLOSE merely minimizes the app to the system tray. I'm not really bent on shutting down the app nicely, but when it's shut down forcefully it leaves the icon in the system tray. Thanks :)
-
pkill - never heard of it. But then again, I've always been a friend of the GNU utilities, which has killall. :) I have now successfully demonstrated that GNU makes you ignorant! :-D
Jörgen Sigvardsson wrote:
pkill - never heard of it. But then again, I've always been a friend of the GNU utilities, which has killall.
The best way to kill processes on Linux that I ever saw was actually a Doom mod where the bad guys were each labeled with a process ID. *Blam* Shoot the bad guy, and it kills the process. Funny stuff, especially when you killed the Doom process itself or a critical OS function. :)