6

I'm trying to get PS to open up instead of cmd.exe when I do a Shift+left-click and select open command window here I changed the %ComSpec% system variable and even added on in my user variable pointing to the PS path, but no result, cmd.exe is still opening up.

I must be doing something wrong, could someone help me please ?

2 Answers 2

5

Inside the registry you can redirect cmd.exe to Powershell.

Start regedit.exe, go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options and create a key cmd.exe. Now create a string (REG_SZ) with the name Debugger and enter the full path to the Powershell.exe

When you now try run cmd.exe, Powershell is started instead.

5
  • Thank you for your answer, it worked for getting powershells to open up as i wanted, but I can't write anything in it, and i'm not even seeing the microsoft credit at a start of a regular PS window. Any idea why ?
    – MimiEAM
    Jun 16, 2013 at 6:58
  • powershell occasionally waits for me to hit enter a few times before a prompt appears. not optimal, but may help. Jun 16, 2013 at 8:23
  • @FrankThomas unfortunately not in my case, but thanks
    – MimiEAM
    Jun 16, 2013 at 11:33
  • 1
    Run Powershell normally and via cmd.exe and run both time ProcessMonitor from sysinternals. Now compare the difference. Maybe you see why Powershell is not loaded when you use the trick. Jun 16, 2013 at 18:48
  • IFEO is designed for debugger injection. The program needs to be aware of this trick, eg. ProcessExplorer. To make this a clean hack, the process needs to sanitize the command line. Otherwise it will pass the original commandline ("cmd.exe") into powershell.
    – Ben L
    Oct 16, 2015 at 20:46
2

Changing the following 3 values did it for me in in Win7 at least. Can't confirm for Win8 right now, but registry locations should be the same (obviously change the path to PowerShell.exe if it's different on your system).

1.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Drive\shell\cmd\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\PowerShell.exe -NoExit -Command \"cd '%v'\""

2.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\cmd\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\PowerShell.exe -NoExit -Command \"cd '%v'\""

3.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\cmd\command]
@="C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\PowerShell.exe -NoExit -Command \"cd '%v'\""

Note 1: You can use %SystemRoot% instead of C:\\Windows if you change the data type of cmd\command\(Default) from the default REG_SZ to REG_EXPAND_SZ.

Note 2: The cd command fails if the current working directory's name contains a single quote. I have asked about this here: Opening PowerShell at the current working directory from the registry.


Another option would be to add a new Open PowerShell Here command to the context menu instead of replacing cmd.

Also, in Win8 you should be able to quickly open PowerShell with Alt+F, R:

1

You must log in to answer this question.

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