• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

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;
0
x4
Asked:
x4
  • 2
1 Solution
 
RickHalleCommented:
The second variable of the CreateProcess function is actually a parameter variable.

BOOL CreateProcess(

    LPCTSTR lpApplicationName,     // pointer to name of executable module
    LPTSTR lpCommandLine,     // pointer to command line string
    LPSECURITY_ATTRIBUTES lpProcessAttributes,     // pointer to process security attributes
    LPSECURITY_ATTRIBUTES lpThreadAttributes,     // pointer to thread security attributes
    BOOL bInheritHandles,     // handle inheritance flag
    DWORD dwCreationFlags,     // creation flags
    LPVOID lpEnvironment,     // pointer to new environment block
    LPCTSTR lpCurrentDirectory,     // pointer to current directory name
    LPSTARTUPINFO lpStartupInfo,     // pointer to STARTUPINFO
    LPPROCESS_INFORMATION lpProcessInformation      // pointer to PROCESS_INFORMATION  
   );

Put the path to the batch file as the first variable and the parameter as the second.

Rick Halle
0
 
RickHalleCommented:
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
0
 
x4Author Commented:
Thanks dont know why I didn't figure that out myself.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now