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. CreateProcess and Detect when tthis process Ends..

CreateProcess and Detect when tthis process Ends..

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
4 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.
  • D Offline
    D Offline
    Drakesal
    wrote on last edited by
    #1

    Hi all, i am writing a program that opens an explorer window, when CreateProcess open new window the main program must be minimized when i will close Explorer.exe i want that program return in SW_SHOW state. I simply need to detect when Explorer.exe will be Close. I have seen that when i use createprocess with microsoft MSDN example it will check only one time. What i have to do to complete my task please help me :(

    P S 2 Replies Last reply
    0
    • D Drakesal

      Hi all, i am writing a program that opens an explorer window, when CreateProcess open new window the main program must be minimized when i will close Explorer.exe i want that program return in SW_SHOW state. I simply need to detect when Explorer.exe will be Close. I have seen that when i use createprocess with microsoft MSDN example it will check only one time. What i have to do to complete my task please help me :(

      P Offline
      P Offline
      pasztorpisti
      wrote on last edited by
      #2

      It is possible to wait for a program to exit when you start it with CreateProcess() but in your case you shouldn't do that. Many text editor and browser and whatever programs work like this: They allow you to open many documents on tabs. When you use CreateProcess() to start the editing or viewing of a document (or a webpage in your case) you launch an instance of the editor program that does the following: It checks if another instance of that program is already running and if that is the case then the process you created is just passing some info to the already running process and the process you started exits immediately. The already running process shows your document/webpage on a new tab. You shouldn't check for closing the explorer because you can't for the reasons I listed previously, moreover, I know that many users never exit their web browser - they use it open all they with hundreds of tabs for some reason.

      1 Reply Last reply
      0
      • D Drakesal

        Hi all, i am writing a program that opens an explorer window, when CreateProcess open new window the main program must be minimized when i will close Explorer.exe i want that program return in SW_SHOW state. I simply need to detect when Explorer.exe will be Close. I have seen that when i use createprocess with microsoft MSDN example it will check only one time. What i have to do to complete my task please help me :(

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

        You can wait on a process handle:

        STARTUPINFO si = { sizeof(si) };
        PROCESS_INFORMATION pi;
        BOOL bOk = CreateProcess(
        _T("C:\\Windows\\system32\\notepad.exe"),
        NULL,
        NULL,
        NULL,
        FALSE,
        0,
        NULL,
        NULL,
        &si,
        &pi
        );
        if (bOk)
        {
        CloseHandle(pi.hThread); // We don't need so don't leak it!
        WaitForSingleObject(pi.hProcess, INFINITE);
        CloseHandle(pi.hProcess); // We're finished with it.

        MessageBox(NULL, \_T("Finished"), \_T("Create and wait"), MB\_OK);
        

        }

        Steve

        D 1 Reply Last reply
        0
        • S Stephen Hewitt

          You can wait on a process handle:

          STARTUPINFO si = { sizeof(si) };
          PROCESS_INFORMATION pi;
          BOOL bOk = CreateProcess(
          _T("C:\\Windows\\system32\\notepad.exe"),
          NULL,
          NULL,
          NULL,
          FALSE,
          0,
          NULL,
          NULL,
          &si,
          &pi
          );
          if (bOk)
          {
          CloseHandle(pi.hThread); // We don't need so don't leak it!
          WaitForSingleObject(pi.hProcess, INFINITE);
          CloseHandle(pi.hProcess); // We're finished with it.

          MessageBox(NULL, \_T("Finished"), \_T("Create and wait"), MB\_OK);
          

          }

          Steve

          D Offline
          D Offline
          Drakesal
          wrote on last edited by
          #4

          Thanks for ask I have tried your solution and it goes good when i need to close my opened app, but i need this: i want open an explorer.exe window and when i close my caller program i need that program closes explorer window too. Do you think it's possible?

          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