4

I have a batch file and an application developed in delphi7. Both are working fine. I want to run the batch file when clicking a button. what can I do for that?

Thanks Nelson

2 Answers 2

8

Use ShellExecute which is declared in ShellAPI.

ShellExecute(
    MainForm.Handle,
    'open',
    PChar(scriptfilename),
    PChar(params),
    PChar(workingdirectory),
    SW_SHOW
);
Sign up to request clarification or add additional context in comments.

5 Comments

@Nelson Does this answer the question?
@DavidHeffernan Can we use CreateProcess instead of SE? how?
To use CreateProcess you'd have to send it cmd.exe as the executable, and then whatever arguments are needed to run the script. Typically that would be /C scriptfilename.bat
@DavidHeffernan if you mean passing 'cmd.exe /C scriptfilename.bat' as 'lpCommandLine' I've already tried it.. I'm using RunDosInMemo, it only shows an empty cmd window, and my app stops on until (Apprunning <> WAIT_TIMEOUT) loop till I close cmd manually, however the command runs OK from Run window. should I change anything in RunDosInMemo?
@saastn I can't do this in comments to an unrelated question. If you've got a question about the code you have, ask it.
0
 var
 exe_start_map:string;
 begin
  exe_start_map:=(ExtractFileDir(Application.ExeName));     
   winexec(PChar(exe_start_map+'\yourfile.bat'),sw_show);
 end;

you must add ShellApi in uses list

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.