Solved

Create Process and Parameter.

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

947 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

19 Experts available now in Live!

Get 1:1 Help Now