3

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?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
kgh
  • 157
  • 1
  • 12

2 Answers2

2

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.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
404
  • 8,022
  • 2
  • 27
  • 47
0

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.

lit
  • 14,456
  • 10
  • 65
  • 119