[windows-7] Changing default startup directory for command prompt in Windows 7

How do I change default startup directory for command prompt in Windows 7?

I usually do the following to start command prompt from C:\

  WIN-R (Run Prompt)
  cmd /K cd C:\

I want to do the following to start command prompt from C:\

  WIN-R (Run Prompt)
  cmd

This question is related to windows-7 command-prompt

The answer is


While adding a AutoRun entry to HKEY_CURRENT_USER\Software\Microsoft\Command Processor like Shinnok's answer is the way to go it can also really mess things up, you really should try to detect a simple cmd.exe startup vs a script/program using cmd.exe as a child process:

IF /I x"%COMSPEC%"==x%CMDCMDLINE% (cd /D c:\)

Keep the opening of the command prompt clean. Avoid editing the registry key and adding an Autorun, it may come back to bite you.
Create a simple batch file and save it in the C:\Windows or C:\Windows\System32 folder. I call mine !.bat (exclamation mark). It has the following commands:

@echo off c: cd \ cls whoami

It goes to the folder where I need to work, clears the screen and tells me what security context I'm in.


I think the easiest way is to make a cmd shortcut, then change the shortcut's "Start in" directory to the one you want to start with.

described_image


One easy way to do it + bonus.

Start cmd with administrator rights, the default directory for the prompt will be C:\WINDOWS\system32.

I created a bat file in that directory (notes.bat) Opened it with notepad and wrote the following lines. Each line is followed with a comment which should not be added to the bat file.

@echo off

prompt $S$CYourNamel$F$S$G$S 
/* This is a comment, do not include it in the bat file - above line will make the prompt look like  (YourName) > */

cd C:\Your_favorite_directory
/* This is a comment, do not include it in the bat file - above line will navigate you to your desired directory */

Saved the file and that was it. Now when You open cmd with admin rights, just write: notes or notes.bat and it will execute the notes.bat file with desired changes.


Edit: It actually seems that editing the file shortcut breaks the Win+x, c key shortcut. (Moral of the story: only change system files you know how to fix! Eventually after a Windows update it repaired itself.)

What I ended up doing is creating a new customized Command Prompt shortcut in the start folder and pinned to the taskbar that I launch instead of cmd.exe


As other answers point out, changing the registry Autorun cmd start location is a bad idea because it silently will break other programs that shell out for tasks, like Visual Studio Code.

You should just change whatever shortcut you use to open cmd to have a Start In entry.

If you use Win+x, c to launch cmd, you can edit the Start In for

"%LOCALAPPDATA%\Microsoft\Windows\WinX\Group3\02 - Command Prompt.lnk"

  1. go to regedit ( go to search and type regedit)
  2. expand "HKEY_CURRENT_USER" node
  3. under HKEY_CURRENT_USER node expand "software" node
  4. under software node expand "microsoft" node
  5. under microsoft node click on "Command Processor"
  6. path looks like this : "HKEY_CURRENT_USER\Software\Microsoft\Command Processor"

it looks something like this :

  1. if you do not see "Autorun" String Value
  2. Right Click - New - Expandable String Value, and rename it to Autorun
  3. double click on "Autorun" 10.enter this value path format:
  4. "CD/d C:\yourfoldername\yoursubfoldername"

This doesn't work for me. I've tried this both under Win7 64bit and Vista 32.

I'm using the below commandline to add this capability.

reg add "HKEY_CURRENT_USER\Software\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "IF x"%COMSPEC%"==x%CMDCMDLINE% (cd /D c:)"


Open regedit and browse to this path

HKEY_CURRENT_USER\Software\Microsoft\Command Processor

Create new string vale named Autorun. Set its value to cd /d C:\.

Run cmd again. Voila!


Use Windows Terminal and configure a starting directory. Partial settings.json:

{
    // Make changes here to the cmd.exe profile.
    "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
    "name": "Command Prompt",
    "commandline": "cmd.exe",
    "hidden": false,
    "startingDirectory": "C:\\DEV"
},

regedit worked great. HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\Command Processor, all you have to do is change the AutoRun key value, which is already set to wherever you are currently getting dumped into to a new value in the format of:

cd /d <drive:path>

for c:\, that would be cd /d c:\
for junk, that would be cd d/ c:\junk

its very simple, even a novice thats never used regedit should be able to figure it out. if not, go to the c:\prompt and just type in regedit, then follow the path to the key.


On windows 7:

  1. Do a search for "cmd" on your Windows computer
    1. right-click cmd and left click "Pin to start menu" (Alternatively, right-click cmd - click copy and then paste to your desktop )
    2. right-click the cmd in your start menu or on your desktop (depending on choice 2 above) - left click properties
    3. inside the "start in" text box paste the location of your default start directory
    4. Press Apply and OK

Every time you click on the cmd in your start menu or your desktop shortcut, the CMD will open in your default location


"start in directory" command

cmd /K cd C:\WorkSpace

but if WorkSpace happens to be on different than C drive, console will be launched in default folder and then you still need to put D: to change drive To avoid this use cd with -d parameter

cmd /K cd -d D:\WorkSpace

create a shortcut and your fixed ;)


The following solution worked well for me. Navigate to the command prompt shortcut in the start menu:

C:\Users\ your username \AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\Command Prompt

Right click on the shortcut file to open the properties dialog. Inside the "Start in:" textbox you should see %HOMEDRIVE%%HOMEPATH%. If you want the prompt to start in C:\ just replace the variables with "C:\" (without quotes).

update

It appears that Microsoft has changed this behavior recently and so now an additional step is required. After performing the steps above copy the modified shortcut "Command Prompt" and rename it to "cmd". Then when typing "cmd" in the start menu it should once again work.


Easiest way to do this

  1. Click "Start" and type "cmd" or "command prompt".
  2. Select Top most search application named exactly same "cmd" or "command prompt".
  3. Right Click on it and select "Send To"=>"Desktop".
  4. On Your Desktop New "cmd" Shortcut will appear
  5. Right Click on that icon and choose "properties"
  6. Popup will appear, In "Shortcut" Tab Type the new location in "Start In" option (e.g D:\xyz)
  7. Drag that icon and add/pin it in "Task Bar"

In the new Windows Terminal, you can click Settings and edit the line "startingDirectory" to achieve something similar.

Please note, however, that this changes the default startup directory only in Windows Terminal, and not for the command prompt globally.


changing shortcut under Windows System on 8.1 worked for me - another thing I found is that 'Start In:' WORKS when Advanced -> Run as admin is UNCHECKED, however, if CHECKED, it does not work


Bit late but ignore the registry mods. Simply change the shortcut target to:

cmd /k "command"

i.e.

cmd /k "cd\myStartUpFolder"

Voila!


Make a shortcut pointing to cmd.exe somwhere (e.g. desktop) then right-click on the copy and select "properties". Navigate to the "Shortcut" menu and change the "Start in:" directory.


type

cmd.exe /k cd c:/

in a text file and save as cmd.bat Clicking this file does the trick. You can pin it to the start menu as well.

To start in a partitioned drive (e.g. D), use

cmd.exe /k d:

HKEY_CURRENT_USER\Software\Microsoft\Command Processor

string: Autorun value: cd /d %~dp0

all bat files will run from the bat file location


hi if you want cmd to automatically open when the machine starts up you can place the cmd.exe executable in the startup folder(just search for startup and place a shortcut of cmd.exe there)


On Windows Start Menu, right click on Command Prompt.

Click on "Properties".

"Command Prompt Properties" dialog box opens.

Edit the field "Start in " to a location where you want to start the command prompt.

Example: Chand %HOMEDRIVE%%HOMEPATH% to D:\PersonalPrograms.

Next time when you start command prompt the start up directory will be D:\PersonalPrograms


My default dir was system32 when starting CMD. I then created a batch file in that directory to change dir to the one I was after.

This caused me to always call that bat when starting CMD every time. So I made a reg file & put this inside:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"Autorun"="cd C:\\Users\\Me\\SomeFolder"

After saving it, I opened the file, clicked ok to merge with registry, and since then every time I open CMD, I get my dir