Link to home
Start Free TrialLog in
Avatar of x4
x4

asked on

Create Process and Parameter.

I was wondering if anyone knew how to execute a batch file with a paramater attached.
I can use the code below to just exe the batch file but when I try to add the parameter at the end (NAME).
It drops out.

Procedure
var
  Name: string;

begin
  Name := TEST;
  FileToRun := C:\TEMP + 'RUN.BAT ' + NAME;
  if CreateProcess(nil, PChar(FileToRun), nil,
     nil, false, NORMAL_PRIORITY_CLASS, nil, nil,
     startinfo, proc_info) <> False then
  begin
    // The process has been successfully created so execute it and wait
    // until it ends while still processing the form
    while MsgWaitForMultipleObjects(1,Proc_Info.hProcess,
    false, INFINITE, (QS_POSTMESSAGE Or QS_SENDMESSAGE))
    <> WAIT_OBJECT_0 do
    begin
        Forms.Application.ProcessMessages;
    end;
    // Process has finished. So close the window
    //CloseHandle(proc_info.hProcess);
    // take out because dos window closes by itself
  end;
end;
ASKER CERTIFIED SOLUTION
Avatar of RickHalle
RickHalle

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 RickHalle
RickHalle

To see more information on this click on the CreateProcess function in your code and hit the F1 key. This was taken directly from the Delphi help files.

Rick Halle
Avatar of x4

ASKER

Thanks dont know why I didn't figure that out myself.