Solved

Create Process and Parameter.

Posted on 2001-08-22
3
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

696 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