Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to call batch file in Delphi program?

Status
Not open for further replies.

delphihandle

Programmer
Aug 15, 2002
2
US
Hi, all..
I am not a delphi programmer! But, recently I have come across a delphi program, which I need to modify to call a batch file from within a Delphi program.
Can anybody please help me?
Thanks..
 
A good example of doing it was supplied by RSi2 in thread thread102-331406.

--- markus
 
That code is a bit OTT Markus, in most cases a simple call to shellexecute or the more user friendly executefile will work OK.
I really depends on if the Delphi program needs to do an immediate check on the batch file results.

Steve.
 
Hey, Steve.
Thanks for your guidance.
In fact, I just want to invoke a batch file. That's it. I don't need the results. So, which one do you suggest would be more helpful?
~ delphihandle
 
Hi DH

'Shellexecute' is the lowerlevel Windows API funtion it takes lots of parameters that you may not need and you must cast strings into pchars when you pass filenames to it.

You can find 'Executefile' in Delphi\demos\doc\filemanex\fmxutils.pas
it is simply an inteface for shellexecute.
Have a look at the executefile funtion It takes less parameters and you can pass normal strings also if you look at the code it will show you how to call shellexecute directly.

The disadvantage is that you must include the whole module.
and you are using someone else's code, but fmxutils has some other useful proceedures for a beginner, eg filecopy

hope this helps Steve
 
Here is the code for ShellExecute...

uses ShellApi;

ShellExecute (Handle, 'open',
'x:\filename.bat', nil, nil, SW_Shownormal)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top