Change the default Command Prompt directory

Martin Brinkmann
Nov 16, 2007
Updated • Oct 14, 2015
Windows, Windows tips
|
26

Whenever you open the Command Prompt in Windows you are taken to a default directory which is usually your /Documents and Setting/Username/ directory or /users/username/ directory in newer versions of the Windows operating system.

Most of the time you navigate away from it because you need to access files that cannot be accessed from there, or only by adding the full path of it to the query which is not that practicable.

You can change the default command prompt directory, the directory that you start in when you open the prompt using the following tip. I have set mine to c:\windows\system32 but it is up to you which directory you select as the default command prompt directory on your system.

The change requires you to modify a value in the Registry. To do so press the Windows and R key at the same time to open up the run box on the system. Type in regedit and tap on the enter key on the keyboard to load the Registry Editor. You may receive an UAC prompt on newer versions of the operating system which you need to accept before the Registry Editor opens up.

command prompt change default location

Navigate to the key HKEY_CURRENT_USER\Software\Microsoft\Command Processor and search for the String Autorun in the right window.If you can't find the parameter there right-click on Command Processor and select New > String. Name the string Autorun and click ok. Now double-click the new Autorun entry that you find on the right and enter the following string.

CD /d c:\windows\system32

Replace c:\windows\system32 with the path that you want the command prompt to start in.  The changes take effect immediately after you have made them in the Registry Editor. I suggest you keep the editor open and open a command prompt window to see if the new path is showing up when you do so. The easiest way to do so is to press Windows-R, type cmd and hit enter on the keyboard. If something turns out to be wrong, go back to the editor and verify or change the path information there.

It makes sense to pick a directory that you run commands from regularly and that is not set as a system environment variable or user variable.

Summary
Change the default Command Prompt directory
Article Name
Change the default Command Prompt directory
Description
Find out how to change the starting directory that is active when you open a Windows command prompt window.
Author
Advertisement

Tutorials & Tips


Previous Post: «
Next Post: «

Comments

  1. Alison Souza said on June 18, 2020 at 4:56 am
    Reply

    Heads-up: You might not find “Command Processor” in “HKEY_CURRENT_USER” but in “HKEY_LOCAL_MACHINE” in Windows 10 Pro.
    Thanks for the fix. Hopefully it doesn’t mess with Cmake in catastrophic ways the next time I attempt to build something.

  2. TechLauren said on February 18, 2016 at 4:25 am
    Reply

    Wow thank you so much. All the other fixes of changing the environmental variables did nothing but this worked. No idea why it changed in the first place it certainly never opened in users in the past and what a useless directory to open in! Couldn’t even use any commands to change directory. I am so glad this is fixed and I don’t have to go fishing in my system32 folder for a usable copy of cmd.exe

  3. Chug said on May 30, 2014 at 5:47 pm
    Reply

    The setting works but has (for me) an unwanted side effect:

    Tools such as CMake start putting their output in the directory named by the Autorun entry instead of the directory in which CMake is run. I imagine this is from CMake running a subprocess and moving the subprocess current directory away from the target directory.

    I like this hack but it undercuts tools I need. For that reason I’m out.

  4. CN said on January 28, 2013 at 9:32 am
    Reply

    thanx alot it works very well

  5. sa said on February 4, 2012 at 5:32 pm
    Reply

    thanks alot dear it works..

  6. Ajay said on August 9, 2011 at 5:15 pm
    Reply

    Thank you, it worked perfectly on my Windows 7 as well:)

  7. TR said on June 28, 2011 at 1:51 am
    Reply

    Nice one thanks

  8. a said on September 3, 2009 at 7:53 pm
    Reply

    Nice thing.Thanks……….

  9. Hima said on August 23, 2009 at 9:21 am
    Reply

    thats so easy to tweak!

  10. magicyte said on April 11, 2009 at 8:14 pm
    Reply

    @ Rj

    When here in the registry editor …

    HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor

    … right-click in the white space, if there is no variable named “Autorun” and click “New” in the menu which was opened after the right-click. Name the variable “Autorun”. Select “String” from the choices of the type of variable and click OK (or whatever button there is that signals to add the variable). You should then see a variable called “Autorun” in the margin. Double-click on it and in the “Value:” textbox, put …

    CD /d X:Y

    … where X is your current drive and Y is the folder you want the default prompt to be. If you do not understand this, just ask and it shall be given unto.

    – magicyte

  11. Rj said on April 4, 2009 at 2:36 am
    Reply

    Ummmm i dont c autorun…can anybody help me, im so nooob at this kinda stuff.>=|

  12. Rj said on March 22, 2009 at 6:03 am
    Reply

    I dont c autorun???

  13. Saravana said on March 16, 2009 at 9:12 am
    Reply

    Hi,
    thank you so much

  14. Kent said on August 9, 2008 at 3:37 am
    Reply

    Hi Rarst
    You can open command prompt from a drive by shift right clicking the drive and clicking on the open command prompt here on the popup menu
    Kent

  15. Rarst said on August 6, 2008 at 11:51 pm
    Reply

    >Does anyone know how to do it from the command prompt w/o regedit though?

    Well, cmd help points to those registry settings… If you really want to play around it you can just make .bat (.cmd) file that runs console and goes to directory needed. Something like this:

    cmd /k cd “c:\”

  16. Hank said on August 6, 2008 at 10:11 pm
    Reply

    I actually had a different starting directory and wanted to get back to c:\

    This regedit definitely worked for me.

    Does anyone know how to do it from the command prompt w/o regedit though?

  17. Daniel said on March 3, 2008 at 1:44 pm
    Reply

    sorry im pretty newb. whats this thing that obi posted do? if its complicated then either dont worry or link me to something. thx.

  18. del said on February 13, 2008 at 11:56 pm
    Reply

    then do it manually

  19. pk said on January 15, 2008 at 8:42 am
    Reply

    xp wont let me add to reg.
    can not import, not a reg script, only import binary reg. files.

  20. Tim said on December 27, 2007 at 4:17 am
    Reply

    anubhav, it does work. You’ve got to create the key if it isnt there, create it as a string then edit it to the path.

  21. Manju said on November 26, 2007 at 6:58 pm
    Reply

    Hey anubhav, that does work.
    Thanks Martin.

  22. anubhav said on November 23, 2007 at 11:25 am
    Reply

    no this does not work

  23. Vivek said on November 21, 2007 at 2:29 pm
    Reply

    Nice hack! That’s really clever :)

  24. Martin said on November 16, 2007 at 12:18 pm
    Reply

    No it has not yet Obi, thanks for mentioning it.

  25. Obi-Wahn said on November 16, 2007 at 12:11 pm
    Reply

    Well I’m not sure if this hack was on ghacks allready, but to get a Shell-Context-Menu entry to open the command prompt in a choosen folder, just save this:

    ;start here
    Windows Registry Editor Version 5.00

    [HKEY_CLASSES_ROOT\Directory\shell\cmd]
    @=”Open Command &Promt here…”

    [HKEY_CLASSES_ROOT\Directory\shell\cmd\command]
    @=”cmd.exe /k \”cd %L\””

    [HKEY_CLASSES_ROOT\Drive\shell\cmd]
    @=”Open Command &Promt here…”

    [HKEY_CLASSES_ROOT\Drive\shell\cmd\command]
    @=”cmd.exe /k \”cd %L\”
    ; end here

    into a file (commandprompt.reg) and add it to your registry.

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.