Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Change Command Prompt Default Directory


13 Apr 2010   #1

Windows 7 Enterprise x64
 
 
Change Command Prompt Default Directory

This is a simple registry hack to change the default directory you see when opening command prompt. I like to have it set to the OS root drive, but you can change it to whatever you like. This will keep you from having to use the "change directory" switch every time you open command prompt, which can be more than a little annoying.

1.) Open up registry editor by typing "regedit" [without the quotes] in the search box, and then clicking on the link up top.

2.) Navigate to the key HKEY_CURRENT_USER \ Software \ Microsoft \ Command Processor and search for the string "Autorun" in the left window. If that string is not existing yet, create it. Double-click it afterwards and add the new directory path in the following way: CD /d C:\

3.) If you would like the command prompt to open in the system32 folder, use this string instead:
CD /d C:\windows\system32

4.) Close the registry editor, and then open the command prompt to check your work.

As you can see, you can easily change the default directory to whatever you like. Hope this helps you from being annoyed at the command prompt.

Here's the rusult....




Max


My System SpecsSystem Spec
.

13 Apr 2010   #2

XP Pro SP3 X86 / Win7 Pro X86
 
 

Quote   Quote: Originally Posted by MadMaxData View Post
This is a simple registry hack to change the default directory you see when opening command prompt.
Hi Max... why would you do that?

In your start bar find the command prompt shortcut, make a copy of it in a convenient place...

Right click and select properties... You will see this....

Name:  Capture.JPG
Views: 273
Size:  47.0 KB

In the "Start in" box type the path where you want the command prompt to open.
You can even make multiple copies of the shortcut and have them available to open in any convenient place you like...

Name:  Capture2.JPG
Views: 168
Size:  29.5 KB

In addition there are a number of variables that can be used...

%HOMEDRIVE% = the root folder of your system partition
%APPDATA% = the application data folder for each user
%HOMEPATH% = your user folder
%PUBLIC% = your public folder
%SYSTEMROOT% = windows folder
%PROGRAMFILES% = program files folder
%TEMP% = user's temp folder

and I'm sure there are more...


My System SpecsSystem Spec
13 Apr 2010   #3

Windows 7 Enterprise x64
 
 

Quote   Quote: Originally Posted by CommonTater View Post
Hi Max... why would you do that?
Becuase it's simple, and that's the way I've always done it. Except now I have a .reg file I just double-click on after a clean install. It's among a number of .reg files I use.
My System SpecsSystem Spec
.


13 Apr 2010   #4

XP Pro SP3 X86 / Win7 Pro X86
 
 

Quote   Quote: Originally Posted by MadMaxData View Post
Quote   Quote: Originally Posted by CommonTater View Post
Hi Max... why would you do that?
Becuase it's simple, and that's the way I've always done it. Except now I have a .reg file I just double-click on after a clean install. It's among a number of .reg files I use.
Yeah, well... My way is better...

Hey... whatever works.
My System SpecsSystem Spec
13 Apr 2010   #5

Windows 7
 
 

Also, if you put whatever paths you need in your PATH environment variable, then that will negate the need to have CMD in a different directory in most cases. It won't really matter what directory it defaults to unless you are specifically trying to do something in that directory.
My System SpecsSystem Spec
13 Apr 2010   #6
Microsoft MVP

64-bit Windows 8.1 Enterprise
 
 

My System SpecsSystem Spec
01 May 2010   #7

Windows 7 Enterprise x64
 
 

Quote   Quote: Originally Posted by Brink View Post
In addition to these great options:

Open Command Window Here as Administrator
An easy way to set the Command Prompt to open as Administrator, is to go to Start Orb>>> All Programs>>> Accessories>>> Right click the Command Prompt link>>> Choose Properties>>> Click on Advanced in the Shortcut tab>>> Tick the box to run as Administrator>>> click ok twice to save your setting.

I always run the Command Prompt as Administrator. There's no reason to run it any other way.
My System SpecsSystem Spec
03 Feb 2012   #8

Windows 7 32 bit & Windows 7 64 bit
 
 
There is another way to script this into a batch file...

I found this result by google so, sorry for bringing this out of the archive. I thought you all would like this,

To List the working directory, you can call on the environmental variable of %cd%

For example:
If your trying to make a batch file that copyies a file from a "flash drive" to the desktop, you would normally put something like this:

copy e:\filename.txt c:\users\username\desktop /y

The problem would then be that if you plug the flash drive into a machine where the drive letter E: is taken, your copy command would not work. If you use environmental variables your copy command would look something like this.

copy %cd%filename.txt %userprofile%\desktop /y

P.S. keep in mind if you would like to add in a little debugging, add "&&" to specify an action if sucessful OR "||" to specify an action if NOT successful.

For Example the following would copy the file and if it was NOT successful it would ECHO Copying Failed.

copy %cd%filename.txt %userprofile%\desktop /y||ECHO Copying Failed
My System SpecsSystem Spec
01 Dec 2012   #9

Windows 7 Pro 64-bit
 
 

I came upon this thread when trying to find how to open, from a desktop icon, a Command Prompt window in a directory of my choosing.

It would seem that the specification of a directory path in the "Start in" field in the shortcut will work only when the Command Prompt shortcut is run in normal, or non-elevated, mode.

However, if the box "Run as administrator" is ticked, the Command Prompt window starts with C:\Windows\System32 as the current directory. It is at this point that one needs to use MadMaxData's original Regedit hack, the first post in this thread, to change this to the directory of one's choosing, say D:\MyDirectory - for which I thank him!
My System SpecsSystem Spec
01 Dec 2012   #10

Windows 7 Pro 64-bit
 
 

I came upon this thread when trying to find how to open, from a desktop icon, a Command Prompt window in a directory of my choosing.

It would seem that the specification of a directory path in the "Start in" field in the shortcut will work only when the Command Prompt shortcut is run in normal, or non-elevated, mode.

However, if the box "Run as administrator" is ticked, the Command Prompt window starts with C:\Windows\System32 as the current directory, regardless of whatever directory path has been put in the "Start in" field. It is at this point that one needs to use MadMaxData's original Regedit hack, the first post in this thread, to change this to the directory of one's choosing, say D:\MyDirectory - for which I thank him!
My System SpecsSystem Spec
Reply

 Change Command Prompt Default Directory




Thread Tools



Similar help and support threads for2: Change Command Prompt Default Directory
Thread Forum
Solved How do I change system attribute for all folders using command prompt? Performance & Maintenance
How to restore default Arp settings in Command Prompt?! Network & Sharing
Solved Cannot change drive in command prompt using CD General Discussion
Solved Command Prompt Default Properties General Discussion
Solved Change Directory in Command Prompt General Discussion
Change time to display OS from installation disk command prompt Installation & Setup
Command Prompt to change primary monitor? General Discussion

Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 11:01 PM.
Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App
  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33