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. Kill a process!!

Kill a process!!

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++linuxhelptutorial
3 Posts 3 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.
  • C Offline
    C Offline
    chadell
    wrote on last edited by
    #1

    Hi, This is my problem: I am using VC++ 6.0, and my program has to execute a shell application, this task is accomplished with the "ShellExecute", but my problem starts here. For example, if the command is indefinite (ping 10.0.0.1 -t), How can I kill this process with a VC++ sentence????? without execute the manual CTRL+C sorry for my english, thanks in advance

    B M 2 Replies Last reply
    0
    • C chadell

      Hi, This is my problem: I am using VC++ 6.0, and my program has to execute a shell application, this task is accomplished with the "ShellExecute", but my problem starts here. For example, if the command is indefinite (ping 10.0.0.1 -t), How can I kill this process with a VC++ sentence????? without execute the manual CTRL+C sorry for my english, thanks in advance

      B Offline
      B Offline
      Brian Shifrin
      wrote on last edited by
      #2

      Instead use ShellExecuteEx and get Process handle, followed with TerminateProcess.... Brian

      1 Reply Last reply
      0
      • C chadell

        Hi, This is my problem: I am using VC++ 6.0, and my program has to execute a shell application, this task is accomplished with the "ShellExecute", but my problem starts here. For example, if the command is indefinite (ping 10.0.0.1 -t), How can I kill this process with a VC++ sentence????? without execute the manual CTRL+C sorry for my english, thanks in advance

        M Offline
        M Offline
        Michael Gunlock
        wrote on last edited by
        #3

        Try to avoid TerminateProcess() if possible. See MSDN description of TerminateProcess for the reasoning. Solutions depend on whether the child process has a top level window or are running in a console. I'll assume the child process you describe will be running in a console. One way is to... 1. Spawn child process with ShellExecuteEx() or CreateaProcess() 2. WaitForSingleObject(Handle_To_ChildProcessID,YourTimeOutValue)...consider putting this in worker thread 3. If times out, then kill child process ***NOTE: I have read about others getting CreateRemoteThread to work as described below but I personally have not confirmed this. CreateRemoteThread is available in NT/2K/XP. X| *** - CreateRemoteThread() using the ProcessID handle you got from CreateProcess and passing the address of ExitProcess() as the lpStartupAddress. ExitProcess() appears to be mapped to the same address in each processes address space. You can obtain this address by using the address from your process. - When the remote thread starts (and calls ExitProcess) within the child process, the child process can now "cleanly" terminate. If the child process has a top level window, then just PostMessage(HandleToChildsWnd, WM_CLOSE, 0,0), then confirm the process terminated. Regards Mike

        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