Link to home
Start Free TrialLog in
Avatar of RLopezLo
RLopezLo

asked on

How can use CreateProcess(...) in Delphi 2005 (Vcl.Net)?

In past delphi versions (no .net) I started processes with CreateProcess. Under .net I can't start a process with this routine.
I haven't errors in compilation but the process never start.

I know that there is other ways to start a process but, for me, CreateProcess is the best due to the possibilities of control.

Coul'd someone help me to know the correct way to use CreateProcess?

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of Mark Brady
Mark Brady
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of laes_
laes_

function TForm1.WinExecAndWait32(ExName:String; Arg: String; Dir: String):Cardinal;
   var
    zAppName:array[0..512] of char;
    zCurDir:array[0..255] of char;
    WorkDir:String;
    StartupInfo:TStartupInfo;
    ProcessInfo:TProcessInformation;
    ID : Cardinal;
begin
  StrPCopy(zAppName,ExName);
  GetDir(0,WorkDir);
  StrPCopy(zCurDir,WorkDir);
  FillChar(StartupInfo,Sizeof(StartupInfo),#0);
  StartupInfo.cb := Sizeof(StartupInfo);
  StartupInfo.dwFlags := STARTF_USESHOWWINdow;
  StartupInfo.wShowWindow := 0 ;
  if not CreateProcess(nil, PChar(zAppName + ' "' +Arg+ '"'), nil , nil , false,
   CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil , PChar(Dir) ,StartupInfo,ProcessInfo)
  then Result := 0
  else begin
    WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess,Result);
    Result := 1;
   end ;
end ;