Note: the advice below are not very interesting. You should use the Powertoys (Windows 95/98) or the Windows Resource Kit (NT/2000), which do the same and much more. Thanks to TallRoo and Shannara256 for notifying me about that.

In Windows, it is much easier to navigate in the Explorer than in a DOS window (although this is an oxymoron). Therefore, the easiest way to use a DOS prompt in a directory is to go to that directory in the Explorer, then right-click to open a DOS prompt there. Unfortunately, the OS was not designed to facilitate the life of the user, so there is no such entry in the right-click menu by default. Here is a way to add it.

Of course, this will only interest Windows users. And Use at your own risk, of course.

  1. Go to the HKEY_CLASSES_ROOT\Folder\shell node in the registry (note that Folder includes drives and directories).
  2. Create a new key (from the right-click menu), and call it "DOS prompt".
  3. Under that new key, create a sub-key named "command".
  4. Under that new key (i.e under HKEY_CLASSES_ROOT\Directory\shell\DOS prompt\command), edit the (Default) String value and give it the following value: "c:\winnt\system32\cmd.exe %1" (or whatever the path to cmd.exe is on your system).
  5. Now, you can open a DOS window by right-clicking on any directory name in the Windows explorer.

Actually the above isn't entirely accurate, as far as Windows 2000 goes, and I'd imagine for 95 and 98 as well (though I haven't checked).

First up, the cmd command (ahem) doesn't actually accept a path as a parameter. cmd %1 does nothing. But why does it work then? Because if you right click a folder in windows explorer's folder list (the left hand pane) the environment variable saying what the current path is changes to that folder. The cmd prog loads in this 'current folder' as stored in the environment by default so the path seems to be correct. However, this does NOT work if you click a folder in a listview (ie the right hand pane of windows explorer), because the folder is only highlighted, but the environment doesn't change to that folder. Instead the command prompt window will load up in the folder that CONTAINS the folder you clicked, as this is the 'current' folder.

So what can we do about this? Well, cmd DOES in fact allow you to run commands just after instantiation. Specifically, append: "/k Horses" to cmd, where Horses is some command, and away it goes. So to make this work we put:

cmd /k "cd %1"

cd is the command prompt command for Change Directory.

Note that the command string is in quotes. This isn't strictly necessary, but I feel it makes the whole thing neater.

OK, that works, but we can improve it a bit. If I use my "Command Prompt" option (I prefer Command Prompt to DOS Prompt) on "Program Files", then it comes up in

C:\PROGRA~1>

Ugly. So instead of %1, I'll use %L which, of course, passes the path in long filename format:

cmd /k "cd %L"

gives...

C:\Program Files>

OK, what about Drives? It'd be handy to do the same thing with drives too right? We have two options:

(1) - put our little menu command in the HKCR/Folder key

(2) - put an identical menu command in the HKCR/Drive key

I'm going for Option (2). This is because windows also considers things like the control panel to be folders too, and %L (and %1) don't return paths for these things (which makes sense). This would cause issues, so instead we'll just make a copy in the Drive key.

OK, more fun:

You can put more than one command after the /k - so what about having it list the contents of the dir? Well commands are separated by a pair of ampersands (&&), so the new line goes like this:

cmd /K "cd %L&&dir"

or better still:

cmd /K "cd %L&&dir/w/o/p"

...which adds the parameters to dir to make the list Wide, sOrted and appear Page at a time (with "Press a key..." messages).

I'll leave you to consider the possibilities from here. Here's a standard .REG file with the final above changes. Just copy and paste into a new text file called "whatever.REG", double click, and enjoy. Note that this may not work on earlier versions of windows, you may need to change the 'Version' value to get it going on Win 9x. Also the usual disclaimers apply.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Drive\shell\cmdprmpt]
@="Command Prompt"

[HKEY_CLASSES_ROOT\Drive\shell\cmdprmpt\command]
@="cmd /K \"cd %L&&dir/w/o/p\""

[HKEY_CLASSES_ROOT\Directory\shell\cmdprmpt]
@="Command Prompt"

[HKEY_CLASSES_ROOT\Directory\shell\cmdprmpt\command]
@="cmd /K \"cd %L&&dir/w/o/p\""

Unfortunately even the above isn't enough if you have more than one logical drive.

By default the cd command sets the current directory on the current drive if no drive letter is specified. However, if a drive letter is specified (as it is by %L), then CD changes the path on the specified drive (not necessarily the current drive).

To always open the DOS prompt at the correct location on the correct drive, use the following command:

cmd "cd /d %L"

The "/d" switch tells the CD command to change drive to the drive specified in the given path if it isn't already the current drive.

Log in or registerto write something here or to contact authors.