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. How can I tell if an app has shut down?

How can I tell if an app has shut down?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelpcareer
6 Posts 5 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.
  • P Offline
    P Offline
    Paresh Solanki
    wrote on last edited by
    #1

    I have an program (P1) that runs a long (and unattended) process and then terminates when that process is complete. I do not have the source code for this program and so have no way to change it's behaviour. I can write another program that can start another process, but I need to start it when P1 has completed it's job and not before. So I need a way of detecting when P1 has finished and use that event to start my program. Any help here? Paresh Solanki hombre que trabaja pierde tempo precioso "The man who works is losing precious time." Vuemme

    J M J 3 Replies Last reply
    0
    • P Paresh Solanki

      I have an program (P1) that runs a long (and unattended) process and then terminates when that process is complete. I do not have the source code for this program and so have no way to change it's behaviour. I can write another program that can start another process, but I need to start it when P1 has completed it's job and not before. So I need a way of detecting when P1 has finished and use that event to start my program. Any help here? Paresh Solanki hombre que trabaja pierde tempo precioso "The man who works is losing precious time." Vuemme

      J Offline
      J Offline
      Jeremy Falcon
      wrote on last edited by
      #2

      If your program launches P1, then you can use... WaitForSingleObject(hProcess, INFINITE); This function will not return until the created process is terminated. After P1 is done, then you can call the third program. Jeremy L. Falcon Homepage : Sonork = 100.16311
      "But everybody darlin' sometimes bites the hand that feeds." "Remember in this game we call life that no one said it's fair." "Just because you're winnin' don't mean you're the lucky ones." Song: Breakdown - Album: Use Your Illusion II - Artist: Guns N' Roses

      P 1 Reply Last reply
      0
      • P Paresh Solanki

        I have an program (P1) that runs a long (and unattended) process and then terminates when that process is complete. I do not have the source code for this program and so have no way to change it's behaviour. I can write another program that can start another process, but I need to start it when P1 has completed it's job and not before. So I need a way of detecting when P1 has finished and use that event to start my program. Any help here? Paresh Solanki hombre que trabaja pierde tempo precioso "The man who works is losing precious time." Vuemme

        M Offline
        M Offline
        Martin Ziacek
        wrote on last edited by
        #3

        Use CreateProcess() to start P1. You will get new process handle in the last parameter PROCESS_INFORMATION structure - hProcess. Then you can use this handle to wait for completion of that proces as a parameter for WaitForSingleObject() function. After call to WaitForSingleObject() will finish, you can get exit code of proces with GetExitCodeProcess(), if you will need it. Then you can start it again.

        1 Reply Last reply
        0
        • J Jeremy Falcon

          If your program launches P1, then you can use... WaitForSingleObject(hProcess, INFINITE); This function will not return until the created process is terminated. After P1 is done, then you can call the third program. Jeremy L. Falcon Homepage : Sonork = 100.16311
          "But everybody darlin' sometimes bites the hand that feeds." "Remember in this game we call life that no one said it's fair." "Just because you're winnin' don't mean you're the lucky ones." Song: Breakdown - Album: Use Your Illusion II - Artist: Guns N' Roses

          P Offline
          P Offline
          Paresh Solanki
          wrote on last edited by
          #4

          Thanks, but I have no control over when P1 runs. I just need to know when it's completed. I cannot start P1 from within my app because I have no control over when it should start. Paresh Solanki hombre que trabaja pierde tempo precioso "The man who works is losing precious time." Vuemme

          C 1 Reply Last reply
          0
          • P Paresh Solanki

            Thanks, but I have no control over when P1 runs. I just need to know when it's completed. I cannot start P1 from within my app because I have no control over when it should start. Paresh Solanki hombre que trabaja pierde tempo precioso "The man who works is losing precious time." Vuemme

            C Offline
            C Offline
            Carlos Antollini
            wrote on last edited by
            #5

            Ok, in that case you need to use the psapi.dll... look into code project, you can find a class that look in all process, if you don't find the P1 running, is because the application finished ;) Best Regards Carlos Antollini. www.wanakostudios.com Sonork ID 100.10529 cantollini

            1 Reply Last reply
            0
            • P Paresh Solanki

              I have an program (P1) that runs a long (and unattended) process and then terminates when that process is complete. I do not have the source code for this program and so have no way to change it's behaviour. I can write another program that can start another process, but I need to start it when P1 has completed it's job and not before. So I need a way of detecting when P1 has finished and use that event to start my program. Any help here? Paresh Solanki hombre que trabaja pierde tempo precioso "The man who works is losing precious time." Vuemme

              J Offline
              J Offline
              Jason Henderson
              wrote on last edited by
              #6

              What Martin said is best, but you could also use FindWindow in a while loop. As soon as the window has closed, it will not be found by FindWindow so drop out of the loop.

              Jason Henderson
              quasi-homepage
              articles
              "Like it or not, I'm right!"

              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