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.

Thought I would see if anyone had any pointers on the following situation. I've been customizing command prompt to my needs, and recently changed the prompt for my user. Instead of displaying the path in the prompt, I would like it to always be the window title.

I put a new registry key at

HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Command Processor/AutoRun

with value

title %cd% 

This script runs any time command prompt starts. This works. Whenever I open a command prompt via shortcut, this acts properly.

However, whenever I open a command prompt via right click -> Open Command Prompt Here this apparently doesn't execute. I tried looking at the shell command for open here located at

HKEY_CLASSES_ROOT/Directory/shell/cmd/command

which by default is set to:

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

I tried changing this to:

cmd.exe /s /k "cd %1 & title %cd%"

The "%1" was suggested at other places online for an open-here script, and If I understand correctly the & should execute both commands. However, it still does not work every time I open command prompt here. The working directory is indeed correct, the the window title is still "C:\Windows\System32"

Any pointers?

share|improve this question
    
Looks like the %cd% is getting evaluated before the cd is executed. Can't you use "cd %1 & title %1" ? –  Paul Apr 19 '12 at 1:31
    
Doesn't appear to work either, unfortunately. –  Chase Meadors Apr 19 '12 at 1:53
    
Does it work if you hardcode a title? I am wondering if it is getting substituted wrong or just not executed at all. –  Paul Apr 19 '12 at 1:58
    
Aha, it appears as if it ISN'T getting executed at all –  Chase Meadors Apr 19 '12 at 2:11
    
Upon saving the key with a hardcoded path, killing explorer and restarting, it appears the command isn't executed. Open prompt here still works correctly, even though I essentially broke it. I have no idea where the real script could be –  Chase Meadors Apr 19 '12 at 2:13

2 Answers 2

up vote 3 down vote accepted

You were pretty close to solution. For me the following command works:

cmd.exe /s /k "pushd ""%V"" & title %V"

EDIT: There are several places in registry supporting the "Command Prompt Here" shell extension. For this change to work consistently across all objects (directories, drives and special folders), you have to search the registry for all occurrences of cmd.exe /s /k pushd "%V" and replace them with the value above.

share|improve this answer
    
Can you perhaps tell me exactly the address of this registry key? My key apparently isn't being executed at all, as I found out in the above comments. This command probably works, but it seems that wherever I'm putting this key, doesn't actually get executed. –  Chase Meadors Apr 19 '12 at 19:21
    
This is exactly the key you pointed out in your question. This works for standard directories. Maybe you are trying with a special folder like "Desktop"? You have to search registry for all occurrences of cmd.exe /s /k pushd "%V" and replace them. –  MBu Apr 19 '12 at 19:27
    
Aaaaah, Desktop was my test case; I figured it would be a normal directory. I'll try that, thanks! –  Chase Meadors Apr 19 '12 at 19:35
    
Searching all instances of the original command and replacing them by yours works in all cases. You might add that part to the actual answer if you want. –  Chase Meadors Apr 19 '12 at 19:41

Try this website, these guys are really helpful. They have a breakdown of all the switches.

http://ss64.com/nt/cmd.html

And NO I have no affiliation with that website, I'm just trying to be helpful. These guys as well as the SuperUser.com website have helped me on hundreds of occasions.

CMD.exe Start a new CMD shell and (optionally) run a command/executable program.

Syntax
      CMD [charset] [options]
      CMD [charset] [options] [/c Command] 
      CMD [charset] [options] [/k Command] 

Options   
   /C     Run Command and then terminate
   /K     Run Command and then return to the CMD prompt.
          This is useful for testing, to examine variables

   Command : The command, program or batch script to be run.
             This can even be several commands separated with '&' 
             (the whole should also be surrounded by "quotes")

   /T:fg  Sets the foreground/background colours 
   /X     Enable extensions to CMD.EXE
   /Y     Disable extensions to CMD.EXE 
   /A     Output ANSI characters
   /U     Output UNICODE characters (UCS-2 le)
          These options will affect piping or redirecting to a file.
          Most common text files are ANSI, use these switches
          when you need to convert the character set.
   /D Ignore registry AutoRun commands
      HKLM | HKCU \Software\Microsoft\Command Processor\AutoRun
   /F:ON Enable auto-completion of pathnames entered at the CMD prompt
   /F:OFF Disable auto-completion of pathnames entered at the CMD prompt (default)At the command prompt Ctrl-D gives folder name completion and Ctrl-F gives File and folder name completion.

These key-strokes will display the first matching path. Thereafter, repeated pressing of the same control key will cycle through the list of matching paths. Pressing SHIFT with the control key will move through the list backwards. 
   /Q    Turn echo off
   /S    Strip quote characters from the command_line
   /V:ON Enable delayed environment variable expansion 
         this allows a FOR loop to specify !variable! instead of %variable% 
         expanding the variable at execution time instead of at input time. 
   /V:OFF Disable delayed environment expansion.

   Environment expansion preference can be set permanently in the registry
   HKLM | HKCU  \Software\Microsoft\Command Processor\DelayedExpansion
   Set to either 0x1 or 0x0

   /knetdiag /debug 
   /knetdiag /fix

   The knetdiag switches are undocumented and work in XP only
   they list and (may) fix these networking issues.If /C or /K is specified, then the remainder of the command line is processed as an immediate command in the new shell. Multiple commands separated by the command separator '&' or '&&' are accepted if surrounded by quotes.

The following logic is used to process quote (") characters:

  1. If all of the following conditions are met, then quote characters on the command line are preserved:
    • No /S switch (Strip quotes)
    • Exactly two quote characters
    • No special characters between the two quote characters, where special is one of: & < >( ) @ ^ |
    • There are one or more whitespace characters between the the two quote characters
    • The string between the two quote characters is the name of an executable file.
  2. Otherwise, old behavior is to see if the first character is a quote character and if so, strip the leading character and remove the last quote character on the command line, preserving any text after the last quote character. To negate this behaviour use a double set of quotes "" at the start and end of the command line. Full Screen The key combination ALT + ENTER will switch a CMD window to full screen mode. press ALT + ENTER again to return to a normal Window. Command.com vs CMD.exe All the commands on these pages assume you are running the 32 bit or 64 bit command line (cmd.exe)

The old 16 bit command processor command.com is supplied to provide backward compatibility for 16 bit DOS applications. Command.com has very limited functionality compared to cmd.exe e.g. it will fail to set an %errorlevel% after many commands.

If you name your batch scripts with the extension .CMD rather than .BAT then they will not run under command.com even if copied to a Windows 95 machine.

The %COMSPEC% environment variable will show if you are running CMD.EXE or command.com

One key difference between .CMD and .BAT scripts (running under CMD.EXE) is that with extensions enabled, commands like PATH/APPEND/PROMPT/SET/ASSOC will reset ERRORLEVEL to 0 if they succeed. In the old style .BAT file, the ERRORLEVEL will not be changed unless there is a new error (source). On 64 bit versions of Windows, the 32 bit CMD.exe can be found at %windir%\SysWoW64\cmd.exe To reduce compatibility issues, the WOW64 subsystem isolates 32-bit binaries from 64-bit binaries by redirecting registry calls and some file system calls. Opening CMD from Windows Explorer You can open a new CMD prompt by choosing START, RUN, cmd, OK Registry Keys: ;Allow UNC paths at command prompt [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor] "DisableUNCCheck"=dword:00000001

; Run a command when CMD.exe starts [HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor] "AutoRun"=-

; Activate Automatic Completion [HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor] "CompletionChar"=0x9

; For Windows 7: Add an elevated 'Open CMD prompt here (Admin)' option to the ; context menu for file system folders: [HKEY_CLASSES_ROOT\Directory\shell\runas]@="Open CMD prompt here (Admin)" [HKEY_CLASSES_ROOT\Directory\shell\runas\command] @="cmd.exe /k pushd %L"

; For Windows 7: Add an elevated 'Open CMD prompt here (Admin)' option to the ; My Computer context menu: [HKEY_CLASSES_ROOT\CLSID{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\runas] @="Open CMD prompt here (Admin)" [HKEY_CLASSES_ROOT\CLSID{20D04FE0-3AEA-1069-A2D8-08002B30309D}\shell\runas\command] @="cmd.exe"History of Previous Commands Pressing the UP arrow will list previous commands entered at the command prompt. Other DOSKEY function keys are loaded by default (F7, F8, F9) Copy and Paste / QuickEdit To simplify the use of cut and paste at the Command Prompt, enable QuickEdit mode as follows: Activate the control menu at the top left of the current cmd window, go to Properties, Options tab and then tick against QuickEdit Mode. Now you can select text with the mouse and hit Enter (or right click) to copy it to the clipboard. Paste anywhere using Control+V (or Right Click) or via the menu. ESC will cancel any selection and return to editing mode. When copying between windows, you may need one click to select the window and a second click to paste. Run multiple instances of CMD.exe At the command line or in a batch script CMD will start a new instance of CMD.exe which will appear in the same window. The EXIT command will close the second CMD instance and return to the previous shell.

A method of calling one Batch script from another is to run a command like CMD /c C:\docs\myscript.cmd

The output of CMD can be redirected into a text file. Notice that where CMD /c is used, the EXIT command is not required.

The environment Variable %CMDCMDLINE% will expand into the original command line passed to CMD.EXE The native version of CMD.exe is always in %windir%\system32, on 64 bit operating systems there is also a 32 bit CMD.exe in %windir%\SysWOW64

Pausing or stopping a batch script Execution of any batch script can be paused by pressing CTRL-S This also works for pausing a single command such as a DIR listing Pressing any key will resume the operation.

Execution of any batch script can be stopped by pressing CTRL-C

If one batch file CALLs another batch file CTRL-C will exit both batch scripts. If CMD /c is used to call one batch file from another then CTRL-C will cause only one of the batch scripts to terminate. (see also EXIT)

Long Commands and long filenames Under Windows XP, the CMD command line is limited to 8,191 characters. For all versions of Windows, NTFS and FAT allows pathnames of up to 260 characters.

A workaround for the limited pathname length is to prefix \?\
for example:
\?\C:\TEMP\Long_Directory\Long_Filename.txt
ErrorLevel
CMD /C will return an errorlevel, for example CMD /c dir Z: where the drive Z: does not exist, will return %errorlevel% = 1 to the calling CMD shell.
Command Extensions
Much of the functionality of CMD.exe can be disabled - this will affect all the internal commands, Command Extensions are enabled by default. This is controlled by setting a value in the registry: HKCU\Software\Microsoft\Command Processor\EnableExtensions Alternatively under Win XP you can run CMD /e:on or CMD /e:off
Examples:
Run a program and pass a Filename parameter:
CMD /c write.exe c:\docs\sample.txt
Run a program and pass a Long Filename:
CMD /c write.exe "c:\sample documents\sample.txt"
Spaces in Program Path:
CMD /c ""c:\Program Files\Microsoft Office\Office\Winword.exe""
Spaces in Program Path + parameters:
CMD /c ""c:\Program Files\demo.cmd"" Parameter1 Param2
Spaces in Program Path + parameters with spaces:
CMD /k ""c:\batch files\demo.cmd" "Parameter 1 with space" "Parameter2 with space""
Launch Demo1 and then Launch Demo2:
CMD /c ""c:\Program Files\demo1.cmd" & "c:\Program Files\demo2.cmd""
“Those who can command themselves, command others” - Hazlitt

Related:

EXIT - Use this to close a CMD shell and return.
CALL - Call one batch program from another
START - Run a program, command or batch file
DOSKEY Edit command line, recall commands
Q156276 - Cmd does not support UNC names as the current directory
Powershell: You may run the CMD shell under Powershell, Exit will return you to the PS prompt.
Equivalent bash command (Linux): bash - run the bash shell (also csh, ksh, sh)

share|improve this answer
    
Can you add more information on what exactly to do in this situation? –  Chipperyman Mar 15 at 4:33

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.