Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Politely closing an app

Politely closing an app

Scheduled Pinned Locked Moved The Lounge
htmlcomtools
14 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K krism42

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

    J Offline
    J Offline
    Jorgen Sigvardsson
    wrote on last edited by
    #2

    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)

    K 1 Reply Last reply
    0
    • K krism42

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

      N Offline
      N Offline
      NormDroid
      wrote on last edited by
      #3

      How much would one pay for such a utility ;) Blogless

      1 Reply Last reply
      0
      • J Jorgen Sigvardsson

        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)

        K Offline
        K Offline
        krism42
        wrote on last edited by
        #4

        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.

        J 2 Replies Last reply
        0
        • K krism42

          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.

          J Offline
          J Offline
          Jorgen Sigvardsson
          wrote on last edited by
          #5

          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

          K Q 2 Replies Last reply
          0
          • K krism42

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

            D Offline
            D Offline
            Duncan Edwards Jones
            wrote on last edited by
            #6

            Is Task Manager :: End task polite enough for you '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd

            K 1 Reply Last reply
            0
            • K krism42

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

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #7

              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

              K 1 Reply Last reply
              0
              • D Duncan Edwards Jones

                Is Task Manager :: End task polite enough for you '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd

                K Offline
                K Offline
                krism42
                wrote on last edited by
                #8

                Yes, except that this is for a script from the command line. :)

                1 Reply Last reply
                0
                • L Lost User

                  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

                  K Offline
                  K Offline
                  krism42
                  wrote on last edited by
                  #9

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

                  L 1 Reply Last reply
                  0
                  • J Jorgen Sigvardsson

                    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

                    K Offline
                    K Offline
                    krism42
                    wrote on last edited by
                    #10

                    Just be thankful it doesn't recursively make you ignorant. :-P

                    1 Reply Last reply
                    0
                    • K krism42

                      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.

                      J Offline
                      J Offline
                      Jorgen Sigvardsson
                      wrote on last edited by
                      #11

                      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.

                      K 1 Reply Last reply
                      0
                      • K krism42

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

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #12

                        In that case find the WM command that does close the app. (Spy++ gvies the numerical value of buttons) Nunc est bibendum

                        1 Reply Last reply
                        0
                        • J Jorgen Sigvardsson

                          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.

                          K Offline
                          K Offline
                          krism42
                          wrote on last edited by
                          #13

                          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 :)

                          1 Reply Last reply
                          0
                          • J Jorgen Sigvardsson

                            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

                            Q Offline
                            Q Offline
                            QuiJohn
                            wrote on last edited by
                            #14

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

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups