4

I am trying to use cmd from Delphi to apply some commands. I use following code

ShellExecute(Application.handle, 'runas', 'cmd.exe',
  PChar('/c command to do '), nil, SW_show);

I want to run more than one command in the same execution, for example

/c command1 command2 command3

I already made a bat file to run some commands. But I don't like the idea of storing a bat to my project. Can I apply more than one command in one execution? Can this be done?

5
  • Do you need to use a command interpreter. Can't you use API functions instead. Commented Jan 5, 2017 at 8:41
  • i dont know if there is api to do commands instead of using cmd it self in delphi i will search about that Commented Jan 5, 2017 at 8:58
  • How do you think cmd does it. It isn't turtles all the way down. Commented Jan 5, 2017 at 9:07
  • @Vlark.Lopin IOW, what specific commands are you wanting to run? There is most likely API functions to accomplish the same actions more directly. Commented Jan 5, 2017 at 16:33
  • @RemyLebeau i will run some netsh commands , the answer helps to do all of them Commented Jan 6, 2017 at 6:15

1 Answer 1

6

You can try separating commands with &&, here is working example

  ShellExecute(Application.handle, 'open', 'cmd.exe',
    PChar('/c "copy /Y file1.txt file2.txt&&copy /Y file2.txt file3.txt"'), nil, SW_show);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you a lot ! As a side note, one must declare the ShellAPI in the Uses first

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.