[Lazarus] TProcess

Antonio Fortuny a.fortuny at sitasoftware.lu
Thu Feb 21 13:47:49 CET 2013


Hi folks.

I'm trying to launch a new process from a running program. This runs on 
a WinCE hand held computer. To achieve this I do in the calling program:

with TProcess.Create(nil) do try
   CommandLine := wNewName;
   Options := [poNewProcessGroup];
   Logger.Add(Format('  Pocket program launching "%s"', [wNewName]), 0);
   try
     Execute;
   except
     on E: Exception do begin
       Msg := Format(DM.Constante[122], [E.Message]);
       Logger.Add(Format('  Pocket program launching error "%s"', 
[E.Message]), 0);
       Result := False;
       Exit
     end;
   end;
finally
   Free
end;

The only thing I get is a "87" exception code: The parameter is incorrect.
Got the same error if I use CreateProcess, like:
function LaunchProcess(const APath: String): Boolean;
var
   si: TSTARTUPINFO;
   pi: TPROCESSINFORMATION;
   Msg: String;
   Error: Integer;
   {$IFDEF WINCE}
   wPath: WideString;
   {$ELSE}
   wPath: String;
   {$ENDIF}
begin
   FillChar(si,SizeOf(TSTARTUPINFO),#0);
   FillChar(pi,SizeOf(TPROCESSINFORMATION),#0);
   si.cb := SizeOf(TStartupInfo);
   si.dwFlags := STARTF_USESHOWWINDOW;
   si.wShowWindow := SW_SHOWDEFAULT;
   wPath := APath;
   {$IFDEF WINCE}
   Result := CreateProcess(PWideChar(wPath), nil, nil, nil, False, 
CREATE_NEW_PROCESS_GROUP, nil, nil, si, pi);
   {$ELSE}
   Result := CreateProcess(nil, PChar(APath), nil, nil, False, 
CREATE_NEW_PROCESS_GROUP, nil, nil, @si, @pi);
   {$ENDIF}
   if not Result then begin
     Error := GetLastError;
     Logger.Add(Format('  Pocket program "%s" launching error %d:"%s"', 
[APath, Error, SysErrorMessage(Error)]), 0);
   end
end;

On a Win32 (Vista) platform it runs without problem using either 
TProcess or CreateProcess.
I cannot use ExecuteProcess because after launching the first program 
has to terminate. It is all in an automatic update process.

Any help would be appreciated.

Antonio.





More information about the Lazarus mailing list