I've seen two different ways of calling icacls
from VBScript:
oShell.Exec("icacls ...
or
oShell.Exec("%COMSPEC% /c Echo Y| icacls ...
What's the difference?
I've seen two different ways of calling icacls
from VBScript:
oShell.Exec("icacls ...
or
oShell.Exec("%COMSPEC% /c Echo Y| icacls ...
What's the difference?
Usually you don't need to run it in a Command Prompt if it's an external command (executable, script, etc.). So if you can go to Start → Run… and run it from there, then you can run your application directly with all arguments, etc.
However, if you're using CMD builtin features, like internal commands (dir
, echo
, mklink
, …), the pipe (|
), or I/O redirection (>
, >>
, <
), you must run the commandline in CMD, because otherwise these features wouldn't be available. The parameter /c
is just to tell CMD to terminate after the command completes. It's not required, but it's good practice to put it there, so you can easily replace it with /k
(keep CMD open after the command completes) for debugging purposes.
Have a look at the documentation for the /C
switch using CMD /?
.
The /C
switch tells the cmd.exe
program to return after it runs the specified command line. If it does not return, you will be left in a cmd
shell. I do not know what this would look like from VBS.
My guess would be that, yes, you need /C
.