CreateProcess() returns false when the commandline contains a path.I don’t understand why.
Here I simplified the operation:
function ExecProcess(path:string):boolean;
var StartupInfo:TstartupInfo;
ProcInfo:TProcessInformation;
begin
FillChar( StartupInfo, SizeOf( TStartupInfo ), 0 );
StartupInfo.cb := SizeOf( TStartupInfo );
Result:= CreateProcess(nil, PChar(path), Nil, Nil, False, 0, Nil, PChar(ExtractFilePath(path)),StartupInfo,ProcInfo);
end;
begin
ExecProcess(ParamStr(0) + ExtractFilePath(ParamStr(0)));
end.
Result is false.
How do I include path in commandline?
If you gave some debugging info such as the values of ParamStr(0) and Path, I think you’d find your own answer.
I think the error is here:
ParamStr(0) + ExtractFilePath(ParamStr(0))
So if your app is c:\apps\foo.exe
then you’re going to be effectively calling:
ExecProcess(‘c:\apps\foo.exec:\apps\’);
I don’t think that’s what you wanted. However, you don’t say what you’re doing, so it’s hard to know for sure….