Kill cmd.exe

Where we are?

How many time have I heard this question from other PowerShell enthusiasts: “when cmd.exe is going to die”. Or at best “when will PowerShell.exe become default when user asks for command line”. It’s not so in Windows 8 Developer Preview, not sure what to expect in final release, but kind of don’t expect it to happen anytime soon. What is most frustrating for some is the fact, that server core still expects us to type “powershell.exe” once we boot.

Where we would like to be?

I’ve used cmd.exe for years. Never jumped on the vbscript wagon so I tried to squeeze every last drop from cmd.exe (must admit – I missed opportunity with wmic.exe, and came back to it when I was already using PowerShell for some time on legacy boxes where PowerShell was not an option). But for me – now when most of clients and servers in my organization have PowerShell on by default – I would like to hide it, just in case, and have PowerShell as my primary command line experience.

How to get there?

I’ve seen some tweaks to add PowerShell here and there. My answer is more general. Once you use this trick – you will have cmd.exe replaced everywhere. Any instance of cmd.exe will just pass you straight to PowerShell.exe. If you run it from other tool, if you run it from Explorer.exe ‘File’ menu in Windows 8, if you go to start > Search program and files in Windows 7 and type ‘cmd.exe’ there…

All you have to do is add one registry key either to:

HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor


HKEY_CURRENT_USER\Software\Microsoft\Command Processor

The name of the property is ‘AutoRun’, it’s either Expandable String or just String. Tested on Windows 7, Windows 8 Server Developer Preview, Windows 2008 R2 (full server, no core virtuals on my box at the moment). In first try you can put simple “powershell.exe” there, and most of people should not need anything else. I’ve decided to resign from my usual profile (it’s quite heavy), change the title, and because I added command – I need to tell PowerShell to stay once it’s done:


And final result…? Just typed ‘cmd’ in explorer window on my Windows 7 box. And look what I got? PowerShell AT LAST! Uśmiech


And there is no much to code here:

$ReplaceCmd = @{            
    Path = 'HKLM:\SOFTWARE\Microsoft\Command Processor'            
    Name = 'AutoRun'            
    Value = 'powershell.exe -noexit -noprofile $host.UI.RawUI.WindowTitle = ''PowerShell AT LAST'''            
New-ItemProperty @ReplaceCmd -Force

How to get back?

The answer is simple: one time – just type exit in PowerShell and you are back with your old friend. Don’t like this trick and what to have cmd.exe back for good? Just delete registry key and forget about it. Uśmiech And because it’s registry you can have it on each and every machine you touch. Handy especially if you know that nobody else would ever want to use command line on particular box.

How much will it cost?

Well… there are at least two things you need to consider before you enable this tweak: do you use .cmd files and do you use cmd /c in your PowerShell scripts. This solution can in effect prevent you from both, so be careful… For /c solution is pretty straight forward: all you have to do is to use /d together with it (cmd /d /c dir e.g.). For .cmd files run by double-clicking is just a matter of registry fixes in HKLM:\Software\Classes\cmdfile\shell. Still a lot other things can go wrong… So remember if it does – check if removing this tweak won’t solve you problem. Uśmiech


3 thoughts on “Kill cmd.exe

  1. I love this like a manifesto, I do not like (or understand) implementation. From windows it’s probably much better to add powershell to path (additionally I always make a short-cat ps1 that points to powershell to type less). You will basically have the same experience, but without side effects.

  2. You are probably right about that. I wrote this article mainly because I realized that we *can* kill cmd.exe already, if we want to try to live without it. I’m not saying it’s the best option, or easiest… Just possible, and not many people know about this, even though possibility to use reg key for ‘cmd profile’ is there for quite some time. 😉

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s