CreateProcess and Detect when tthis process Ends..
-
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 :(
-
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 :(
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 useCreateProcess()
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. -
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 :(
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
-
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
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?