Solved

Create Process and Parameter.

Posted on 2001-08-22
3
207 Views
Last Modified: 2010-04-06
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
Comment
Question by:x4
  • 2
3 Comments
 
LVL 2

Accepted Solution

by:
RickHalle earned 40 total points
ID: 6415411
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
 
LVL 2

Expert Comment

by:RickHalle
ID: 6415420
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
 

Author Comment

by:x4
ID: 6415452
Thanks dont know why I didn't figure that out myself.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Firemonkey allowing RTL on android 6 56
shape, triangle, dbctrlgrid 3 33
Delphi, TImage, Png 2 33
Firemonkey how to swip panel with finger tap 1 25
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question