79

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
IsaacS
  • 3,551
  • 6
  • 39
  • 61
aung
  • 793
  • 1
  • 6
  • 5
  • 4
    Superuser.com might be better suited for this question. – alex Feb 04 '11 at 08:35
  • 4
    I found the least system invasive solution here http://superuser.com/a/155863/12735 – IProblemFactory Dec 22 '12 at 16:26
  • 1
    There's another good answer at http://stackoverflow.com/a/21485003/5016547 – Joseph238 Oct 21 '16 at 15:50
  • Have you tried using the `set` command inside CMD to see the variables that are available? Or considered using something like `%windir%\system32\cmd.exe /K "cd targetdirectory"` as your shortcut? – SDsolar Apr 23 '18 at 19:31

24 Answers24

104

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.

CorayThan
  • 17,174
  • 28
  • 113
  • 161
LightBox
  • 3,395
  • 4
  • 25
  • 38
52

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.

BenOcc
  • 649
  • 5
  • 7
  • 3
    On my Win 8.1, I found the shortcut under `Windows System`, not Accessories. – IsaacS Mar 28 '14 at 21:03
  • 1
    Good answer -- works, no hacks required, won't break other tools. – Thomas W Dec 10 '14 at 00:33
  • 2
    For users using multiple command line interfaces,(GIT BASH, CYGWIN, Language Shells) This is the safest answer. You can even assign the shortcut to a keyboard shortcut. – Nathan Aug 17 '15 at 12:56
  • 1
    Simple and effective, but sadly, it doesn't work when you directly run `cmd.exe`. – Gras Double Nov 02 '15 at 23:16
  • 1
    @GrasDouble, try it again with my updated instructions. It once again works for me. – BenOcc Nov 03 '15 at 19:42
  • Clever! Can be useful for people too used to typing "Win > "cmd" > Enter" :-) – Gras Double Nov 03 '15 at 22:08
  • Though, I'm still doing "Win+R > Enter" ("cmd" being already input, as the remembered last entry). So I put a `cmddesk.cmd` file in my PATH: `@CMD /K CD /D `. I just have to remember typing "cmddesk" instead of "cmd" when it's not in the Win+R box. – Gras Double Nov 08 '15 at 00:49
  • 1
    Best answer, why not this selected? – vzhen Apr 20 '16 at 08:03
  • 5
    On my Windows 10, the cmd shortcut is located in "C:\Users\myusername\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows System" – Joseph238 Oct 21 '16 at 15:46
  • Fantastic, thanks! In Windows 10 it seems that the step under "update" is not necessary. – tsemer Oct 19 '17 at 16:46
42

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!

Shinnok
  • 6,279
  • 6
  • 31
  • 44
  • 13
    I'm pretty sure this will cause problems since scripts and other programs might launch cmd.exe/%comspec% and end up in the wrong directory! – Anders Feb 04 '11 at 15:52
  • 4
    @Anders, yes, you are right, pretty much every invocation of cmd from there on will start on C:, which could potentially break some functionality for scripts and other tools making use of cmd. – Shinnok Feb 07 '11 at 07:43
  • 1
    could potentially break some functionality will certainly break to the ground a vast amount of scripts – Gras Double Nov 02 '15 at 23:23
  • 5
    Doing this will ultimately result in suffering. – Random Geo guy Mar 04 '16 at 22:44
  • I'm a lazy guy. So i need default on C: volume is "c:\folder_name". And then i switch to D: volume, default is "d:\other_folder_name". Can i get it? – Loi Pham Mar 16 '16 at 10:30
  • 3
    Completely forgot that I followed this advice, and spent COUNTLESS hours trying to debug why npm and nodemon were failing. Please don't do this. – Alex Beals Sep 26 '17 at 04:15
  • 1
    Don't do this ! That fails when i'm using `npm run ...` and probably in another programs. – pirs Oct 05 '17 at 01:57
  • This answer should probably be removed. Similarly wasted hours trying to fix issues with far manager before realizing this was the cause. Every command would execute from C:\, for example C:\directory>cd would return C:\. – Szmagpie Oct 25 '17 at 11:15
31

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:\)
Anders
  • 97,548
  • 12
  • 110
  • 164
  • 12
    you can use this command from the command line `reg add "HKEY_CURRENT_USER\Software\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "IF x"%COMSPEC%"==x%CMDCMDLINE% (cd /D c:\)"` – venimus Jun 04 '12 at 16:27
  • 5
    Just a note... I did this and while running any command-line functions such as `grunt` or `bower` it will attempt to use THIS directory rather than the directory you are currently in... Just an FYI – Mike Fielden May 31 '13 at 19:21
  • I got similar breakage with Heroku's command line tools, resulting in its interactions with `git` failing silently. This solution might not be worth the headache depending on what tools you use. – James Nov 11 '14 at 08:30
  • 2
    I ran into a case mismatch issue with this. Had to modify the line slightly to get it to work. /I to add case insensitivity. The issue was with c:\Windows\System32\cmd.exe and c:\Windows\system32\cmd.exe `IF /I x"%COMSPEC%"==x%CMDCMDLINE% (cd /D c:\)` – helios456 May 05 '15 at 17:29
  • how to make it so that it also works when you run cmd as administrator.. with the "run as" option – Alex Sep 08 '16 at 13:33
  • @venimus put your comment reg add "HKEY_CURRENT_USER\Software\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "IF x"%COMSPEC%"==x%CMDCMDLINE% (cd /D c:\)" as answer, it worked for me – Shirish Herwade Jul 28 '17 at 15:50
  • @AlexCurvers for run as admin check https://superuser.com/questions/1067901/how-to-open-command-prompt-in-a-specific-folder-as-administrator – Maverick Meerkat Dec 27 '19 at 16:48
  • I use `reg add "HKEY_CURRENT_USER\Software\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "IF /i x"%USERPROFILE%""%COMSPEC%"==x"%CD%"%CMDCMDLINE% (cd /d c:\)"` which additionally checks for the default working directory (seems to be %USERPROFILE%). This should avoid most problems when cmd ist called from other tools. – stb Dec 21 '20 at 09:26
26

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"
Umair Aziz
  • 1,518
  • 1
  • 19
  • 29
  • running ad administrator always goes to system 32 =( – Andrew Jan 25 '18 at 19:40
  • 1
    making a copy of an answere even after 6 years should not be upvoted! – Dwza Jun 26 '18 at 03:04
  • 1
    @Andrew You can change it by going to HKEY_CLASSES_ROOT\cmdfile\shell\runas\command and then changing default directory arguments in after cmd.exe \C path of exe – Umair Aziz Feb 25 '19 at 10:34
8

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

Russia Must Remove Putin
  • 374,368
  • 89
  • 403
  • 331
kanakangi
  • 81
  • 1
  • 4
6

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

cmd /k "command"

i.e.

cmd /k "cd\myStartUpFolder"

Voila!

Flexo
  • 87,323
  • 22
  • 191
  • 272
jdawg1983
  • 61
  • 1
  • 1
  • This is simple, non invasive and works great. Most of the other answers do not work with Run As Admin setting, which I have checked on my shortcut. – mike nelson May 16 '22 at 05:08
  • In case you have other commands you want to enter you can combine them using the & or && operator but the whole thing must be enclosed in quotes. In case your desired folder is on another drive you can also use the /D option for the "cd" command to switch immediately to the drive.e.g. `cmd /k ""C:\Tools\VsDevCmd.bat" & cd /d d:\projects"` – Shaun Aug 31 '23 at 09:37
5

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:)"

MKANET
  • 573
  • 6
  • 27
  • 51
  • 1
    This is not an answer. If you need to ask the author something, post a comment. If you have a question, then post your own. –  Oct 15 '12 at 19:05
  • 1
    Now that this has been edited, it's a great answer. But I prefer less quotes: `reg add "HKEY_CURRENT_USER\Software\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "if x%COMSPEC%==x%CMDCMDLINE% (cd /d d:\)"`. Command line solutions FTW! – grenade Sep 09 '13 at 09:21
  • To go to your profiles homefolder on your computer, use `reg add "HKEY_CURRENT_USER\Software\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "if x%COMSPEC%==x%CMDCMDLINE% (cd /d %USERPROFILE%)"` – fsteff Nov 16 '18 at 13:50
  • To update the HOMEDRIVE and HOMEPATH variable with your local home folder, and then go to that folder, use `reg add "HKEY_CURRENT_USER\Software\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "if x%COMSPEC%==x%CMDCMDLINE% (set "HOMEDRIVE=%USERPROFILE:~,2%" & set "HOMEPATH=%USERPROFILE:~2%" & cd /d %USERPROFILE%)"` – fsteff Nov 16 '18 at 14:14
3

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

Das_Geek
  • 2,775
  • 7
  • 20
  • 26
joe-khoa
  • 465
  • 1
  • 5
  • 10
2

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

  • From a usability perspective this is the best option. It also doesn't screw up the rest of your environment or require knowing some special key! – epelc Mar 29 '16 at 18:56
1

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

1

HKEY_CURRENT_USER\Software\Microsoft\Command Processor

string: Autorun value: cd /d %~dp0

all bat files will run from the bat file location

guest
  • 11
  • 1
  • Welcome to Stack Overflow! Please don't post answers on obviously off topic / bad questions! [See: **Should one advise on off topic questions?**](http://meta.stackoverflow.com/q/276572/1768232) – Tobi Nary Mar 04 '16 at 10:42
1

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"
Carl Walsh
  • 6,100
  • 2
  • 46
  • 50
1

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.

Vladimir Vagaytsev
  • 2,871
  • 9
  • 33
  • 36
Mihkel
  • 11
  • 3
1
  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"
felix
  • 21
  • 1
0

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:
Pierre
  • 9
  • 1
0

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

Zimba
  • 2,854
  • 18
  • 26
0

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.

0

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"
},
dforce
  • 2,136
  • 3
  • 20
  • 36
0

HKEY_CURRENT_USER\Software\Microsoft\Command Processor is no longer valid.

The new key is here:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor

Change "Autorun" to "CD /d C:\YourFolder" (without double quotes)

Link Phan
  • 1
  • 2
-1

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.

Graeme
  • 1
-1

"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 ;)

kanzo
  • 9
  • 1
-1

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)

-3

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.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140