Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need "cmd /c"?

Tags:

cmd

vbscript

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?

like image 397
kgh Avatar asked Jun 21 '26 04:06

kgh


1 Answers

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.

like image 63
404 Avatar answered Jun 24 '26 06:06

404