There's no good reason to do this. In fact, the only real effect that happens is to slow things down.
People might think there is a good reason to do this. Using CMD has the following effects which can commonly be good in some cases:
- Enables internal commands, like "
DIR
"
- Sets environment variables, such as the PATH variable
However, in this case, neither of those benefits are gained. Let's look at both of these scenarios:
So, there can, in some cases, be a time when using "CMD /C
" is useful. For example, if I use the external command PSEXEC
(downloaded from SysInternals), and try to run "DIR
" on a remote computer, then Windows will try to run the "DIR
" command. Windows will fail to run that command since there is no "DIR.EXE
", "DIR.BAT
", or "DIR
" file ending with another supported extension. (Supported extensions can be seen by running "ECHO %PATHEXT%
".)
However, in this scenario, if I try to run "CMD /C DIR
", then that will work, because Windows will look for an executable named "CMD
", and will find that, and then CMD
will end up successfully running the "DIR
" command which is an internal part of the "CMD
" command.
In this case, you can just run powershell
just as easily as "CMD /C powershell
", so you gain no benefit from the unnecessary "CMD /C
". The only benefit I'm seeing to going through the extra step of typing "CMD /C
" is to provide an example which will be useful if somebody decides to try modifying an example to run a command line "DIR
" or "COPY
". Having a more flexible example may be useful for some people. It's really not needed when people know what they're doing.
As for the second bullet point I provided, which is to set environment variables, that's also something that you're not actively doing in this particular case. Maybe some people think that they are helping matters by causing the PATH environment variable to be set. However, when you run commands directly (e.g., from the "Run" menu option of the Start menu), the Windows operating system may look for commands in some additional places. For instance, in Windows XP / newer you can run:
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"
If the command you want to run is listed under "App Paths", Windows may find the program even if it isn't in the path. So, Windows is likely to find even MORE than just what CMD would find in the PATH that CMD uses.
One possible benefit is if you wanted CMD to be run so that you could refer to an environment variable like %USERPROFILE% or %LOGONSERVER% or %TEMP%/%TMP%, but since you're not doing that, you're not needing to run "CMD /C
".
So, for your particular case: There's no good reason to do it. The effects you are achieving are having your computer do more work, slowing the process down, and using up more memory (all of which you are doing by negligible amounts on modern equipment).
2None of the answers in the linked question use
cmd /c
...cmd /k
is rather different in that it leaves the window open after the command completes. Presumably the asker did it that way so they could see the output for debugging purposes. – Bob – 2017-09-01T02:43:12.2931It's not so much the modifier I'm wondering about, ti's the use of
cmd
at all, which seems to be ubiquitous from my research. – stib – 2017-09-01T02:45:16.427Can you provide a reference that actually recommends
cmd /c powershell
specifically? Again, the one you linked makes no such recommendation. – Bob – 2017-09-01T02:45:42.163the accepted answer here: https://social.technet.microsoft.com/Forums/scriptcenter/en-US/bf9b7b21-8cc6-4ff2-bfa2-f96de2cde699/run-script-from-explorer-contextrightclick-menu?forum=ITCG
– stib – 2017-09-01T02:47:30.747also https://stackoverflow.com/questions/31792202/adding-powershell-command-to-windows-context-menu-and-escaping-quotes-properly
– stib – 2017-09-01T02:49:52.2833At a guess, it's probably mostly cargo culting. There's a few cases where this might be desired (namely, when you want to use cmd constructs like piping), but they don't really apply when you can do the same in powershell anyway. There is nothing in MSDN documentation that suggests this is necessary, though the docs surrounding file associations are rather sparse. – Bob – 2017-09-01T03:21:00.290