When App2 runs App3, App3 gets run the exact same way regardless of whether App2 was run directly or by App1. So there is no way that App1 running App2 could be affecting how App3 gets run by App2.
What CAN be affected is App2's initial working directory, and thus App3's initial working directory. So you should always use absolute paths, not just for parameter values but also for the .exe paths as well. You should also consider using the SHELLEXECUTEINFO.lpDirectory
field to specify an initial working directory. Just so there is no possibility that your apps are looking in the wrong directories while doing their work.
That being said, if you still have the same problem, then I suggest you have App3 output the actual command-line parameters that it received (MessageBox()
, OutputDebugString(), a file, etc). It might be receiving something different than you are expecting, or it may be parsing the parameters incorrectly.
Lastly, on a side note, you can replace your Sleep()+GetExitCodeProcess()
loop with a single call to WaitForSingleObject()
(or MsgWaitForMultipleObjects()
if you need to run a message loop while waiting), and then call GetExitCodeProcess()
once afterwards to get the final result, if needed:
if ShellExecuteEx( @exInfo ) then
begin
if WaitForSingleObject(exinfo.hProcess, INFINITE) = WAIT_OBJECT_0 then
GetExitCodeProcess( exinfo.hProcess, exitcode );
CloseHandle( exinfo.hProcess );
end;