Solved

Create Process and Parameter.

Posted on 2001-08-22
3
202 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now