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 do i Detect if an external program has finished excuting(shellexec)?

how do i Detect if an external program has finished excuting(shellexec)?

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 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.
  • U Offline
    U Offline
    User 404410
    wrote on last edited by
    #1

    I want to execute several external programs in a que. I have to execute one program and wait for it to finish and excute another. Is there a way to detect if a external running program has finished? Thanks

    T R C 3 Replies Last reply
    0
    • U User 404410

      I want to execute several external programs in a que. I have to execute one program and wait for it to finish and excute another. Is there a way to detect if a external running program has finished? Thanks

      T Offline
      T Offline
      Toni78
      wrote on last edited by
      #2

      Now this might sound way off because I don't know what you're trying to do, but you could write a batch file "somefile.bat" and there you can put the names of your programs. I don't know if you're familiar with batch files so for example to execute notepad, paint, and minesweeper one after the other you could just write c:\windows\notepad c:\windows\paint c:\windows\winmine paint won't start until notepad closes and so on. So you can just try to execute this batch file from your program and you won't have to worry about the checking them (unless you want the opposite). // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

      1 Reply Last reply
      0
      • U User 404410

        I want to execute several external programs in a que. I have to execute one program and wait for it to finish and excute another. Is there a way to detect if a external running program has finished? Thanks

        R Offline
        R Offline
        Rage
        wrote on last edited by
        #3

        Use CreateProcess instead of ShellExecute, and use WaitForSingleObject like this :

        // Init structs for process
        STARTUPINFO lpsi;
        lpsi.cb=sizeof(STARTUPINFO);
        lpsi.cbReserved2=0;
        lpsi.lpReserved2=0;
        lpsi.lpReserved=0;
        lpsi.lpDesktop=NULL;
        lpsi.lpTitle="Doing something ...";
        lpsi.dwFlags=STARTF\_USESHOWWINDOW;
        lpsi.wShowWindow=SW\_SHOWMAXIMIZED;
        
        PROCESS\_INFORMATION lppi;
        
        if (CreateProcess(NULL,(LPTSTR)path.operator LPCTSTR), NULL, NULL, FALSE, NORMAL\_PRIORITY\_CLASS, NULL, m\_TotalCompPath.operator LPCTSTR(),&lpsi,&lppi)==0)
        		// Error launching
        	else
        	{
        		WaitForSingleObject(lppi.hProcess,INFINITE);
        	}
        

        ~RaGE();

        1 Reply Last reply
        0
        • U User 404410

          I want to execute several external programs in a que. I have to execute one program and wait for it to finish and excute another. Is there a way to detect if a external running program has finished? Thanks

          C Offline
          C Offline
          cmk
          wrote on last edited by
          #4

          WaitForSingleObject() will allow you to wait on a process handle. It uses the handle from CreateProcess() or OpenProcess(). The handle is signaled when the process terminates and is non-signaled while running. ...cmk

          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