How to change the default startup directory for Command Prompt?Published: Jun 2004
Updated : Dec 2007
Send your feedback
When you open a Command Prompt window (CMD.EXE), it defaults to your user profile home directory. If you wish to change the default startup directory for Command Prompt, use the steps listed in this article.
CAUTION Changing the current directory using Autorun value as mentioned in this article, might affect the functionality of batch scripts. For more information, read the post Hidden gotcha: The command processor's AutoRun setting at Raymond Chen's blog. Also, changing the startup directory using Autorun affects the functionality of the CmdHere Powertoy as well. Read below... If you decide to modify the default startup directory by editing the Autorun value, you do so at your own risk.
Set the default startup directory
- Click Start, Run and type Regedit.exe
- Navigate to the following branch:
HKEY_CURRENT_USER \ Software \ Microsoft \ Command Processor
- In the right-pane, double-click Autorun and set the startup folder path as its data, preceded by "CD /d ". If Autorun value is missing, you need to create one, of type REG_EXPAND_SZ or REG_SZ in the above location.
Example: To set the startup directory to F:\Windows, set the Autorun value data to CD /d F:\Windows
You may also use a batch file so that it executes the contents automatically upon launching the Command Prompt. To view the entire list of arguments supported by CMD.EXE and their description, type CMD /? at the Command Prompt.
You can also set the default Prompt in the Autorun key. To execute more than one command automatically at Command Prompt startup, type the commands in a Notepad document and save as a .BAT file. Then, type the full path to the batch file in the Autorun field in the registry. Sample Batch file:
@echo Welcome to Command Prompt
Open Command Window Here PowerToy adds an Open Command Window Here context menu option on file system folders, giving you a quick way to open a command window (cmd.exe) pointing at the selected folder. The Open Command Window Here functionality is affected if you set the Command Processor Autorun value as described earlier in this article.
To re-enable the functionality of Open Command Window Here PowerToy, and have the Command Processor Autorun feature enabled at the same time, use these steps:
- Click Start, Run and type regedit.exe
- Navigate to the following location:
HKEY_CLASSES_ROOT \ Directory \ shell \ cmd \ command
- In the right-pane, double-click (default) and change the following data:
cmd.exe /k "cd %L"
cmd.exe /d /k "cd %L"
- Exit the Registry Editor
Note: If /D parameter IS specified on the command line, then when CMD.EXE starts, it ignores the AutoRun registry variables in the following locations.
HKEY_LOCAL_MACHINE \ Software \ Microsoft \ Command Processor \ AutoRun
HKEY_CURRENT_USER \ Software \ Microsoft \ Command Processor \ AutoRun