Changing default startup directory for command prompt in Windows 7
Asked Answered
D

24

80

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
Dian answered 4/2, 2011 at 8:32 Comment(4)
Superuser.com might be better suited for this question.Carrageen
I found the least system invasive solution here superuser.com/a/155863/12735Frieze
There's another good answer at https://mcmap.net/q/145041/-changing-default-startup-directory-for-command-prompt-in-windows-7Reathareave
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?Dismissal
F
32

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:\)
Finger answered 4/2, 2011 at 16:0 Comment(8)
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:\)"Tavarez
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 FYIOffoffbroadway
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.Ctesiphon
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:\)Firewood
how to make it so that it also works when you run cmd as administrator.. with the "run as" optionOscillogram
@Tavarez 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 meGendarmerie
@AlexCurvers for run as admin check superuser.com/questions/1067901/…Spheno
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.Splitting
S
105

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.

Spurtle answered 19/2, 2013 at 12:4 Comment(5)
This worked for me, if you want to start in C:\ just add "\" and not "c:\" otherwise it doesn't work.Backsaw
That is pretty much what I did. Much safer and cleaner. BUT like @Backsaw does not appear to work if you run as admin.Kiefer
Just to add, this way you can have multiple cmd shortcuts each pointing to a different startup directory.Spurtle
running as administrator goes to system 32 =(Gauntlett
you don't need to make a shortcut - there is already one you can edit. See answer by @BenOcc - although the path on win10 is slightly differentDilorenzo
C
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.

Cementation answered 31/1, 2014 at 16:25 Comment(6)
On my Win 8.1, I found the shortcut under Windows System, not Accessories.Linus
Good answer -- works, no hacks required, won't break other tools.Rhizocarpous
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.Anomalism
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 <startup dir>. I just have to remember typing "cmddesk" instead of "cmd" when it's not in the Win+R box.Chura
On my Windows 10, the cmd shortcut is located in "C:\Users\myusername\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows System"Reathareave
Fantastic, thanks! In Windows 10 it seems that the step under "update" is not necessary.Lithomarge
A
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!

Agglutinin answered 4/2, 2011 at 8:39 Comment(9)
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!Finger
@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.Agglutinin
<del>could potentially break some functionality</del> <ins>will certainly break to the ground a vast amount of scripts</ins>Chura
Doing this will ultimately result in suffering.Epispastic
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?Geffner
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.Egbert
Don't do this ! That fails when i'm using npm run ... and probably in another programs.Snowinsummer
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:\.Bedaub
I've also had this configuration for months, it worked without me noticing until others mentioned, that certain npm/node cmds stopped working correctly. I quickly caught on, though, because it was throwing weird errors with accessing System32, the root path, or not having permission. Ideally, npm should warn you about this though.Touchy
F
32

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:\)
Finger answered 4/2, 2011 at 16:0 Comment(8)
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:\)"Tavarez
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 FYIOffoffbroadway
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.Ctesiphon
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:\)Firewood
how to make it so that it also works when you run cmd as administrator.. with the "run as" optionOscillogram
@Tavarez 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 meGendarmerie
@AlexCurvers for run as admin check superuser.com/questions/1067901/…Spheno
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.Splitting
S
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"
Sydelle answered 15/4, 2017 at 8:5 Comment(3)
running ad administrator always goes to system 32 =(Gauntlett
making a copy of an answere even after 6 years should not be upvoted!Catheterize
@Gauntlett 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 exeSydelle
A
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

Apache answered 18/10, 2014 at 1:25 Comment(0)
D
6

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

cmd /k "command"

i.e.

cmd /k "cd\myStartUpFolder"

Voila!

Disorientate answered 3/1, 2016 at 11:38 Comment(2)
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.Dynamic
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"Stonewort
B
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:)"

Benue answered 15/10, 2012 at 18:59 Comment(4)
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.Spinney
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!Whilom
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%)"Crossindex
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%)"Crossindex
G
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

Gal answered 7/3, 2020 at 11:44 Comment(0)
E
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

Enrol answered 29/3, 2016 at 9:53 Comment(1)
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!Suspiration
I
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

Invercargill answered 1/9, 2014 at 22:41 Comment(0)
D
1

HKEY_CURRENT_USER\Software\Microsoft\Command Processor

string: Autorun value: cd /d %~dp0

all bat files will run from the bat file location

Drusie answered 4/3, 2016 at 10:23 Comment(1)
Welcome to Stack Overflow! Please don't post answers on obviously off topic / bad questions! See: Should one advise on off topic questions?Biblioclast
G
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"
Gooseneck answered 2/4, 2016 at 17:45 Comment(0)
E
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.

Ellerd answered 29/8, 2016 at 19:4 Comment(0)
B
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"
Bertsche answered 26/10, 2016 at 22:12 Comment(0)
S
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:
Squeamish answered 4/3, 2016 at 7:38 Comment(0)
G
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

Ganoid answered 21/4, 2019 at 16:56 Comment(0)
G
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.

Groundwork answered 31/7, 2019 at 19:17 Comment(0)
C
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"
},
Chandelle answered 25/9, 2020 at 8:50 Comment(0)
J
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)

Johnnyjohnnycake answered 21/10, 2022 at 9:4 Comment(0)
C
-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.

Coom answered 21/10, 2015 at 23:35 Comment(0)
B
-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 ;)

Brotherinlaw answered 2/5, 2016 at 18:56 Comment(0)
W
-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)

Warily answered 9/5, 2019 at 14:56 Comment(0)
C
-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.

Coupon answered 22/2, 2016 at 15:53 Comment(1)
Thanks for letting us know, but repeating another answer is not an answer itself.Aurita

© 2022 - 2024 — McMap. All rights reserved.