6

Suppose I (or any running process) wanted to launch a shell in Windows (7) and issue a command, there are a number of options available. For example, one could:

  1. Bring up the start menu, type cmd, and hit Enter;
  2. Launch the command prompt via a shortcut;
  3. Bring up the command prompt in a third party tool (such as Launchy), or;
  4. Issue some commands in Windows' Run tool (Win+R), which launches the prompt, issues the command and then returns

All of the above methods will (by default) launch cmd.exe (usually located in the Windows\System32 directory).

Recently I have started to favor alternate command line shells, such as Microsoft's very own PowerShell. However, what frustrates me most about using these tools, is that I seem to have to go out of my way to launch commands through them by default.

Is there any way that I can replace the default behaviour of running cmd.exe with another shell, such as PowerShell or Cygwin? Not only so commands that I might issue from the start menu or a launcher will run in that shell, but if other applications want to open a shell, it will open in said default shell.

To be clear, it'd be nice if there was some clean way to approach this (i.e. a registry setting or configuration option somewhere, rather than simply replacing the executable file).

3
  • Not exactly what you asked for but better: code.google.com/p/conemu-maximus5
    – krowe
    Dec 5, 2014 at 23:43
  • Windows' Run tool does not involve cmd.exe in any way. Whatever you type in there is simply passed to a function, ShellExec, which is part of shell32.dll. As evidence, the "dir" command works within the command prompt environment, but it won't work at the Run prompt. That's because "dir" is not a separate executable - it is a command implemented within cmd.exe. And "dir" is not understood by ShellExec. Apr 20, 2016 at 5:00
  • It is possible to put in a registry setting to have another program run in place of cmd.exe: I am not sure it is a good idea, however. See this article
    – NetMage
    Feb 18, 2021 at 21:54

1 Answer 1

7

.1. Bring up the start menu, type cmd, and hit Enter;

Type powershell instead.

.2. Launch the command prompt via a shortcut;

Change the shortcut's target.

.3. Bring up the command prompt in a third party tool (such as Launchy), or;

IIRC, Launchy just uses shortcuts from Start Menu. Some other tools are hardcoded to run cmd.exe.

.4. Issue some commands in Windows' Run tool (Win+R), which launches the prompt, issues the command and then returns

"Run" does not open a shell, cmd or any other, unless you specifically asked for it by typing its name. It runs the given program directly (AFAIK, by using ShellExcuteEx()).

The black window is a Windows Console. It does not mean there's cmd.exe running inside; it could have any console program. (Exactly the same is with Unix terminals; they could have any program running, not necessarily a shell.)


That said, some programs might still honor the %COMSPEC% environment variable.

5
  • I guess my problem is with other applications primarily. For example, in Explorer, hold Shift, right click and then click Open command window here. By default, it opens cmd.exe. What is telling Windows to do that, is that the %COMSPEC environment variable?
    – gpmcadam
    Jul 31, 2010 at 22:16
  • @Bauer: That right click is set in the registry, the commands associated with file type "Folder" or "Directory" (later is filesystem folders only), or by an Explorer extension.
    – Richard
    Aug 1, 2010 at 8:36
  • @Richard: It would be Directory. ("Open command prompt" wouldn't make any sense for non-filesystem folders.) Aug 1, 2010 at 12:38
  • @Bauer: In Windows Vista and newer, it's probably hardcoded to the Explorer shell (but try changing %COMSPEC% anyway). In XP and older, it's either a command verb in Registry\HKCR\Directory\shell or an Explorer shell extension, like @Richard said. Aug 1, 2010 at 12:39
  • 1
    @Gravity: <pedantic>PowerShell (to name one example) is not limited to file system directories: cd HLKM:\software\classes works fine.
    – Richard
    Aug 1, 2010 at 20:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .