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

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

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

      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
      • 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
        #7

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

        K 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
          #8

          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
          • 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
            #9

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

            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