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. General Programming
  3. C / C++ / MFC
  4. Terminate a process

Terminate a process

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
7 Posts 4 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.
  • J Offline
    J Offline
    JM2251
    wrote on last edited by
    #1

    Hi, I want to terminate a process. I have porcessid and HWND. How to terminate using these? Regards, JM

    S K 2 Replies Last reply
    0
    • J JM2251

      Hi, I want to terminate a process. I have porcessid and HWND. How to terminate using these? Regards, JM

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      The first rule of terminating a process is not to do it: prefer asking it to close down nicely. See http://support.microsoft.com/kb/178893[^]. That said, terminating a process is sometimes necessary as a last resort. The TerminateProcess[^] function will do the trick. It requires a process HANDLE but you only have a process id: use OpenProcess[^] to get a HANDLE from it.

      Steve

      R 1 Reply Last reply
      0
      • S Stephen Hewitt

        The first rule of terminating a process is not to do it: prefer asking it to close down nicely. See http://support.microsoft.com/kb/178893[^]. That said, terminating a process is sometimes necessary as a last resort. The TerminateProcess[^] function will do the trick. It requires a process HANDLE but you only have a process id: use OpenProcess[^] to get a HANDLE from it.

        Steve

        R Offline
        R Offline
        R jeev K R
        wrote on last edited by
        #3

        Try this.... HANDLE prHandle = OpenProcess(PROCESS_ALL_ACCESS, TRUE, dwProcessID); if (NULL != prHandle) { TerminateProcess(prHandle, 0); }

        R S 2 Replies Last reply
        0
        • R R jeev K R

          Try this.... HANDLE prHandle = OpenProcess(PROCESS_ALL_ACCESS, TRUE, dwProcessID); if (NULL != prHandle) { TerminateProcess(prHandle, 0); }

          R Offline
          R Offline
          R jeev K R
          wrote on last edited by
          #4

          If you know the hwnd of the window, then you can use SendMessage Function to close the window....

          1 Reply Last reply
          0
          • R R jeev K R

            Try this.... HANDLE prHandle = OpenProcess(PROCESS_ALL_ACCESS, TRUE, dwProcessID); if (NULL != prHandle) { TerminateProcess(prHandle, 0); }

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #5

            I'm not the one asking the question. Your suggestion is the procedure I outlined in my post.

            Steve

            R 1 Reply Last reply
            0
            • S Stephen Hewitt

              I'm not the one asking the question. Your suggestion is the procedure I outlined in my post.

              Steve

              R Offline
              R Offline
              R jeev K R
              wrote on last edited by
              #6

              You are right Stephen, We two are in same direction. I just followed your reply thread. Not opened another thread, that's all. anyway sorry for the confusion.

              1 Reply Last reply
              0
              • J JM2251

                Hi, I want to terminate a process. I have porcessid and HWND. How to terminate using these? Regards, JM

                K Offline
                K Offline
                KarstenK
                wrote on last edited by
                #7

                i suggest to PostMessage WM_CLOSE so the app can terminate in a correct manner http://msdn.microsoft.com/en-us/library/ms632617%28VS.85%29.aspx[^]

                Press F1 for help or google it. Greetings from Germany

                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