Start and kill program from within program
So I have a subprogram that I need to run at various stages throughout my main program. This program also needs to be in a separate window.
I've got the program opening with this code:
But it runs in the window of the main program. How do I get it into it's own separate place?
char szPath = "C:\\Dev-Cpp\\UKGS\\standAloneSerial.exe";
PROCESS_INFORMATION pif; //Gives info on the thread and..
//..process for the new process
STARTUPINFO si; //Defines how to start the program
ZeroMemory(&si,sizeof(si)); //Zero the STARTUPINFO struct
si.cb = sizeof(si); //Must set size of structure
BOOL bRet = CreateProcess(
szPath, //Path to executable file
NULL, //Command string - not needed here
NULL, //Process handle not inherited
NULL, //Thread handle not inherited
FALSE, //No inheritance of handles
0, //No special flags
NULL, //Same environment block as this prog
NULL, //Current directory - no separate path
&si, //Pointer to STARTUPINFO
&pif); //Pointer to PROCESS_INFORMATION
if(bRet == FALSE)
MessageBox(HWND_DESKTOP,"Unable to start program","",MB_OK);
CloseHandle(pif.hProcess); //Close handle to process
CloseHandle(pif.hThread); //Close handle to thread
Also, I'll need to terminate this process from a completely different part of the program. What's the best way to get the handle in order to use TerminateProcess()?
Thanks a bunch.