How can I execute a batch file with two parameters?

Go To


I have a batch file and an application developed in Delphi 7. I want to run the batch file with set two parameters on it, when clicking a button. How can I do that?

2012-04-04 05:34
by nasrin pournejaty


You can certainly do this with CreateProcess() as described by @Remy. However, CreateProcess() is not the easiest of functions to operate. For convenience you may find ShellExecute() to be a more amenable option:

ShellExecute(0, 'open', PChar(BatchFileName), 'param1 param2', 

Ultimately this will lead to the COMSPEC variable being read and then a call to CreateProcess() being made. The advantage is that you let the shell do the heavy lifting for you.

2012-04-04 22:44
by David Heffernan
Yes I used this command , but Didn't Answer for my exe - nasrin pournejaty 2012-04-05 05:09
I don't understand your comment. What exe and what about it - David Heffernan 2012-04-05 06:50
+1 @DavidHeffernan would you recommend this method to execute an existing .vbs file too? or should I use Windows Script Interfaces (seems like overkill to me) - Sam 2013-06-05 06:27
@Sam This would work fine for a .vbs file. It might be more tricky to capture errors that the script returns - David Heffernan 2013-06-05 06:41


Use CreateProcess() to run "cmd.exe /C batchfilename parameters", where the path to cmd.exe is gotten from the %COMSPEC% environment variable.

2012-04-04 22:39
by Remy Lebeau