Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Following up on this question over at SO (How do I open cmd window in specific location?) I'm looking for an effective way to add the Open Command Prompt Here shortcut to a context menu. Various solutions propose adding entries to HKCR\Folder and others suggest adding entries to HKCR\Directory.

Based on this question (Directory Vs. Folder) it seems a folder could be virtual or not while a directory is always "real". A ven diagram would have folder being a large circle and directory a smaller circle completely enclosed within the folder circle.

For the sake of a command prompt, is it correct to assume I'll probably only be dealing with "real" folders, or directories?

The questions then are as follows: Can I open a command prompt window in a virtual directory and what conceivable reason would I have for doing this? Would adding a context menu item ONLY to HKCR\Folder cover all my bases and then some? Would adding a context menu item ONLY to HKCR\Directory end up missing some things?

Finally, for brownie points: What if I wanted to be able to add an entry to open a command prompt by clicking inside a folder rather than on a folder icon, which context menu item would I have to use to get this function?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

The best way I did it was add the Open command prompt to all objects. The open command prompt passes the working directory (cmd /k pushd %d") and you get the command prompt on the working directory of the object you right clicked.

For the most part, you CAN open a command prompt in a virtual folder. It depends though. For example, DFS folders return a command prompt at a UNC. But trying to get a command prompt on an object in a search folder just gets you the real location of the object.

Edit:

To get the command prompt when you right click the background requires that you write a shell extension. And since Microsoft insists shell extensions be written in native code !me :( See the MSDN on the shell extension menu.

http://msdn.microsoft.com/en-us/library/cc144067(v=vs.85).aspx

Or you could just download this program: Context Console Shell Extension.

http://code.kliu.org/cmdopen/

share|improve this answer
1  
@music2myear: There's a * entry under HKCR. –  afrazier Jul 15 '11 at 15:51
1  
@surfasb: There's a very, very good reason that MS insists on native code for shell extensions - a process can only host a single instance of the .NET framework. What do you think happens if you try to load 3 shell exts, each requiring a different revision of the .NET FW (e.g., 1.1, 3.0, and 4.0)? Things break. –  afrazier Jul 15 '11 at 15:53
1  
It's an unfortunate (or fortunate depending on who you are) reality. I first learned to code in C++ but quickly realized I would never excel at it. Probably would of done more harm than good. So it's managed code for this lifetime. –  surfasb Jul 15 '11 at 18:25
1  
@music2myear: I suggest you read the link and all the links under the Shell extension section. If that is too much effort, just download the Shell extension. . . –  surfasb Jul 15 '11 at 18:26
1  
Yeah, the extension is well written. The source code link is on the same page. BTW, I did read all those links and I can assure you, it is not worth it for a non-native coder. –  surfasb Jul 15 '11 at 18:49
show 2 more comments

For your bonus question: There's no registry key you can modify that lets you do what you want. Install ContextConsole to get that functionality. A shell extension is required in this instance because when you click on the background of a folder, you don't have any object selected.

For your other questions: You can CD to a virtual folder in the Command Prompt if it's backed by a real folder in the file system (e.g., Fonts or Start Menu). Purely virtual folders (e.g. Control Panel) have no filesystem path, so no way to CD to it.

PowerShell supports namespace extensions and allows for doing things like setting your location to a registry path:

PS C:\> Set-Location HKLM:\Software\Classes\Directory
PS HKLM:\Software\Classes\Directory> Get-ChildItem


    Hive: HKEY_LOCAL_MACHINE\Software\Classes\Directory


SKC  VC Name                           Property
---  -- ----                           --------
  2   0 Background                     {}
  0   1 DefaultIcon                    {(default)}
  2   1 shell                          {(default)}
  4   0 shellex                        {}

If you want to add reg keys to HKCR\Directory, add them to HKCR\Drive too if you need them to show up got the drive's root folder too.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.