Search code examples
delphicommand-lineshellexecute

Delphi Executing command line command


I am trying to run a command-line command from inside my Delphi application.

ShellExecute(Form1.Handle, 
             'open', 
             'cmd.exe',
             'icacls "C:\ProgramData\My Program\File" /grant Users:F',
             nil,
             SW_NORMAL);

Note: The command its self works perfectly.

However when I run this code in Delphi I get the command window popping up but the command I want to execute doesn't run or even appear in the command window.

Any idea as to what I am missing?


Solution

  • The command string needs something in front of it.

    /c - will cause it to run

    /k - will cause it to run and not disappear when done