I want to write a code that starts a process and kills mine when the other process is killed.
Do you know good solutions?
My current code:
std::string exeFile{ ExePath() + "\\DTMlibrary.exe" };
if (is_file_exist(exeFile.c_str()))
{
ShellExecute(NULL, "open", exeFile.c_str(), NULL, NULL, SW_SHOWDEFAULT);
EndDialog(0);
}
else
{
MessageBox("Setup DTMlibrary.exe not found ", "System Information", MB_ICONINFORMATION);
EndDialog(0);
}
What you can do - is make parent process wait until child process exit, and then shut down the parent.
Win API legacy functions, like
ShellExecute
do not return process identifier, which can be used by parent process to wait a child process to exit. So you would have to use coreCreateProcess
system call directly. Then you can make parent process to await a child process to exit/terminate. You can useWaitForSingleObject
Win API synchronization function for this.Following example demonstrate the described technique:
Also if you are able to use boost process, code will looks like following:
My advice you'd better don't read this MSDN page