Why doesn't "Open console here" open cmd on the correct drive if not used on the C-Drive?

7,964

Solution 1

Having examined the registry and asked people on chat, I've determined that the parameters being passed to the instance of cmd that was invoked here were incorrect.

The command can be found in [HKEY_CLASSES_ROOT\Directory\shell\cmd\command] and I had a (Default) value of:

cmd.exe /k cd \"%L\"

Changing this to the following value (obtained in that brief chat session) has resolved the issue:

cmd.exe /s /k pushd \"%V\"

That said, while the problem is fixed, I don't know what caused this change initially...

Solution 2

The self-answer by DMA57361 clearly has solved the original problem. I thought I'd add some info I discovered....

First, I noticed a suspicious value in the key HKEY_CLASSES_ROOT\Directory\shell\cmd named Extended. On a hunch, I renamed that value to xxx-Extended and now the "Open command window here" menu item often appears without the Shift key. Since the old tweak-ui solution didn't require the shift key, this discovery makes me happy!

Second, my relatively unmodified Windows 7 Pro 64-bit installation has the registry key HKEY_CLASSES_ROOT\Directory\shell\cmd\command with only a default value of cmd.exe /s /k pushd "%V" set (Note that the type is REG_SZ, not REG_EXPAND_SZ. The meaning of %V (and the reported usage of %L) are not the result of environment variable substitution, and the expansion must be done by Explorer itself.)

The available context menu plugins are listed as subkeys of the registry key HKEY_CLASSES_ROOT\Directory\shellex\ContextMenuHandlers. (The other keys in ....\shellex are handlers for other kinds of shell extensions.) One of those handlers, or perhaps one of the other extensions, is probably the origin of the strange default value of the ....\command key.

Edit A neighboring key, HKEY_CLASSES_ROOT\Directory\Background\shell\cmd, also has a value named Extended. It turns out the this one controls the context menu in the folder's content view (right pane, and the desktop itself) while the one named above controls the context menu of folder objects themselves (their icons on the right or on the desktop, or anywhere on the folder tree on the left).

Solution 3

pushd is required if you want Windows 7 to switch drive letters to the directory i.e. switch drive also.

The registry key needed looks like the following (I call it DOS) - put it into a .reg file and execute:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Folder\shell\DOS]

[HKEY_CLASSES_ROOT\Folder\shell\DOS\command]
@="\"C:\\WINDOWS\\SYSTEM32\\CMD.EXE\" /s /K  pushd \"%v\""
Share:
7,964
DMA57361
Author by

DMA57361

Software Developer, working primarily with Ruby on Rails. Elected ♦ moderator on Super User in the 2011 Elections. After a period of inactivity, I stepped down from this position in 2013. And please, feel free to call me DMA. Places you can find me online: @DMA57361 Steam Github Bitbucket

Updated on September 17, 2022

Comments

  • DMA57361
    DMA57361 over 1 year

    When I [Shift + Right-Click] a folder that isn't on my C drive and select "Open console here" I get a cmd window up that isn't opened at the correct location, but instead is pointing at C:\Windows\system32. I have to manually switch to the correct drive, but when I do it is then at the correct folder. This is hardly the end of the world, but it's a minor annoyance that's really starting to get on my nerves...

    Note: It does work correctly for locations on the Cdrive.

    Is this the expected behaviour when used outside of C?

    If not, how do I fix it?
    If it is, how can I change it to load folders of other drives directly?


    For example, if I attempt to open a console window pointing at a folder on my desktop, like so:

    Selecting "Open console here" from shift+right click menu for folder on desktop

    I get a cmd window pointing at C:\Windows\system32 that I have to manually switch to the D:, but upon doing so you can see that the folder within D: has been selected successfully:

    CMD window that initially shows C:\win\sys32 folder, but a single "D:" command changes to correct location.


    Update

    It seems "Open console here" might be non-standard (see comments).

    For completeness, it turns out that I see the probably standard "Open command window here" lower down the list when clicking inside a folder (it's "file space", not on the folder icon itself), as per the image below, so there's some difference between the two that's cropped up:

    shift+RMB menu when opened directly from desktop (with nothing highlighted)

    • RBerteig
      RBerteig over 13 years
      I can't reproduce this on Win 7 Pro 64-bit. The menu reads "Open command window here" and it does. I tried both a mapped network drive and an actual physical drive.
    • uxout
      uxout over 13 years
      I also can't replicate this on Win 7 Ultimate 64-bit SP1. Like @Rberteig, it works fine for me. I almost wonder if you have a shell extension or something that's conflicting?
    • DMA57361
      DMA57361 over 13 years
      Hmmm, I'm at work now, but if I shift-rmb inside a folder (ie, not on a folder icon itself, but within it's "file space") or directly on the desktop there is a seperate "Open command window here" option available much lower down the list (which I'd not spotted before...) and that works. @Shinrai - do you have the same option as me in the same place? If not, I've also thinking some extension is a play. (Suppose I should add this is Win 7 Pro x64 as well.)
    • DMA57361
      DMA57361 over 13 years
      @Rberteig - please see my previous comment (split as only 1 @ reply per comment). Specifically -- do you have the same option as me in the same place? If not, I've also thinking some extension is a play.
    • RBerteig
      RBerteig over 13 years
      @DMA57361, I'll double check at the office, but I don't believe I do. I don't have very many (or any?) extensions installed, so that sounds like a plausible source of the difference.
    • uxout
      uxout over 13 years
      @DMA57361 - Oh, I didn't notice this subtle difference. I am actually using "Open command window here", but it's in the same place as your "Open console here" when I shift+right-click a folder. When I just do it inside an explorer window it is much lower down the list but it's still "Open command window here". Probably your "Open console here" is from a shell extension. xD
    • DMA57361
      DMA57361 over 13 years
      @Shinrai - well, thanks for checking, it leads me closer to a solution... now just to work our why my option has a different name... :)
  • DMA57361
    DMA57361 over 13 years
    I'll accept this answer (unless someone manages to post something more useful) once the two-day self-accept restriction expires.
  • JdeBP
    JdeBP over 13 years
    No need for PUSHD. Use the /D option to CD.
  • DMA57361
    DMA57361 over 13 years
    @JdeBP indeed, that does seem to work. But, since I just obtained the above by getting someone else to look at their Win7 this doesn't come with any reasoning. Do you happen to have a reason why your suggested method would be better than the one I've already ended up with experimentally?
  • RBerteig
    RBerteig over 13 years
    I can confirm that my Win7 pro 64 uses pushd as above. I don't know why they use pushd instead of cd /d.
  • JdeBP
    JdeBP over 13 years
    PUSHD does additional work above what CD /D does. Only if you want that additional work done is it appropriate. It, of course, pushes the prior current directory onto the directory stack. But it also, presuming that CMD extensions are enabled, goes around creating temporary drive letters in certain circumstances.
  • DMA57361
    DMA57361 over 13 years
    Some useful information, especially about disabling the Extended option, so have a +1. Thanks for the input!