CreateProcess - Running an app that runs an app?
Posted on 1997-05-04
I hope someone out there has an answer for this. I'm using CreateProcess in an application to Execute another
application (not mine) and this all works fine with the following code, the problem is that the application I
am executing in certain situations (about 75% of times) will itself execute another program, and when it
attempts to do this it just hangs, if I kill my program at this stage the it (the application mine started)
can then continue to run the program it's running without any problems. I've tried changing the creation flags
to CREATE_NEW_CONSOLE but no luck. So does anyone have any ideas, any help would be appreciated! BTW My application must wait until the other program terminates the program it runs and itself, and this must all work in WIN95/NT
Function WinExecAndWait(Path : string; Visibility : word) : word;
STARTUPINFO : TStartupInfo;
PROCESS_INFORMATION : TProcessInformation;
FError : Integer;
zCmdLine : Array [0..512] of Char;
STARTUPINFO.cb := sizeof(STARTUPINFO);
STARTUPINFO.dwFlags := STARTF_USESHOWWINDOW;
STARTUPINFO.wShowWindow := Visibility;
// Start the child process.
if not (CreateProcess( Nil, // No module name (use command line).
zCmdLine, // Command line.
Nil, // Process handle not inheritable.
Nil, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
Nil, // Use parent’s environment block.
Nil, // Use parent’s starting directory.
STARTUPINFO, // Pointer to STARTUPINFO structure.
PROCESS_INFORMATION ) // Pointer to PROCESS_INFORMATION structure.
DroneMain.Memo1.Lines.Add('CreateProcess failed: ' + StrPas(zCmdLine))
DroneMain.Memo1.Lines.Add('Executing: ' + StrPas(zCmdLine));
// Wait until child process exits.
WaitForSingleObject( PROCESS_INFORMATION.hProcess, INFINITE );
// Close process and thread handles.
CloseHandle( PROCESS_INFORMATION.hProcess );
CloseHandle( PROCESS_INFORMATION.hThread );