how to set PowerShell as default instead of cmd.exe

6

1

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 ?

MimiEAM

Posted 2013-06-16T04:45:44.587

Reputation: 505

Answers

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.

magicandre1981

Posted 2013-06-16T04:45:44.587

Reputation: 86 560

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 – 2015-10-16T20:46:34.763

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 – 2013-06-16T06:58:52.753

powershell occasionally waits for me to hit enter a few times before a prompt appears. not optimal, but may help. – Frank Thomas – 2013-06-16T08:23:14.807

@FrankThomas unfortunately not in my case, but thanks – MimiEAM – 2013-06-16T11:33:51.767

1Run 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. – magicandre1981 – 2013-06-16T18:48:50.977

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

Karan

Posted 2013-06-16T04:45:44.587

Reputation: 51 857