47

How can I create a desktop shortcut that opens up Command Prompt (cmd) in a specific folder? I'm getting tired of navigating from my home directory to my development directories.

1
  • 1
    Typing cmd in the address bar of any folder in Windows Explorer opens it in the folder too (I'm on Windows 10, not sure if it works in older versions!) Aug 2, 2018 at 11:00

8 Answers 8

53

Create your shortcut and then right click to get the properties dialog and set the "Start in:" property to be your folder.

setting the start folder

If you are running the shortcut as an administrator you should add your desired path to the target (instead of "start in"), for example:

%windir%\System32\cmd.exe /k cd c:\crp

or

%windir%\System32\cmd.exe /k pushd c:\crp

because the "start in" value is ignored when running as administrator (all credits go to @barlop for their answer and @T_D for their comment)

6
  • 1
    This does not seem to work for any drive other than where your system is installed.
    – WORMSS
    Feb 11, 2015 at 15:14
  • 11
    When Properties > Shortcut Tab > Advanced > Run as administrator is enabled, this solution does not work. Aug 21, 2015 at 14:44
  • 2
    @JosephDykstra in that case you should add your desired path to the target (instead of "start in"), for example: %windir%\System32\cmd.exe /k cd c:\crp or %windir%\System32\cmd.exe /k pushd c:\crp because the "start in" value is ignored when running as administrator (all credits go to @pacoverflow his answer superuser.com/a/1067902/550943 here). Cheers!
    – T_D
    Jan 7, 2020 at 14:09
  • 1
    @T_D - it's superuser.com/users/42672/barlop - who wrote that answer, but thanks for finding it!
    – ChrisF
    Jan 7, 2020 at 14:14
  • @ChrisF ah yep, the answer got edited
    – T_D
    Jan 8, 2020 at 8:16
11

Or you could just use a target string similar to this:

C:\Windows\system32\cmd.exe /k "c: & cd c:\drv\bat"

Obviously C:\Windows\System32\cmd.exe is to run cmd. The /k carries out the command by string and continues. The string is the "c: & cd c:\drv\bat". Within the string, the c: just changes the drive letter. The & ties both commands together. And the cd c:\drv\bat is basically a change directory. Also one thing to note, the cd c:\drv\bat should also change drives.

1
  • 1
    Isn't that "cd /d <path>" for paths on another drive? Oct 23, 2015 at 7:30
6

There's more than one way to skin this cat, for sure.


A batch file could also do it for you. This will start you off in the Program Files directory on the C drive:

@ECHO OFF
CD /D "C:\Program Files\"
CMD

Especially make sure to use the /D switch, if you're changing to a different drive than where CMD normally starts you.


The Open Command Window Here PowerToy for Windows XP is also rather handy for going straight from an Explorer session, into a CMD console at a certain directory.


You can use the AutoRun string value in one of the following Registry keys, to essentially automate the above for all CMD sessions.

For your account only:

HKCU\SOFTWARE\Microsoft\Command Processor\

For all users on this machine:

HKLM\SOFTWARE\Microsoft\Command Processor\

If the AutoRun value doesn't exist, create it as a REG_SZ type (also known as String Value). For Data, you can either put the path to a batch file like the one above (remove the ECHO and CMD lines) or just insert the CD command as shown in the above example.

The up-side of pointing the Registry to a batch file, instead of just adding the command, is that you can add in as many AutoRun commands as you like to the batch file. This way you can create custom prompt formats or script other tasks you want done at every launch of CMD.

One thing to keep in mind if you make these Registry changes though, is that they may affect the behavior of other batch files. Particularly, batch files may find themselves not starting in the directory they were originally written for.

As always, backup your Registry before making any untested changes.

2

Answering 7 years after the question asked :-)
It might help someone anyway!

To have the shortcut work with Run as Administrator option enabled:

Insert your commands separated with an & In the Target text box of the Properties dialog after /k switch. Don't forget that the commands containing folder names with spaces (e.g., Program Files), should be enclosed in double quotation marks.

The following example

  • opens command prompt
  • runs Node.js batch file
  • switches to drive D
  • goes to code directory

C:\Windows\System32\cmd.exe /k "D:\Program Files\nodejs\nodevars.bat" & d: & cd d:\code

2
1

Insurgence's answer didn't work for me, but this did. For me, I wanted to launch a cmd shell, run the node vars batch file, and then change dir to my repo root (c:\source\myproject). Here's the command, note the double quotes:

cmd /k ""C:\Program Files\nodejs\nodevars.bat" && cd \source\overlay"

Additionally, to get really fancy and launch angular, I use:

cmd /k ""C:\Program Files\nodejs\nodevars.bat" && cd \source\overlay && ng serve -o"
0

You can go to the directory where the cmd.exe shortcut is located by default (the one that comes up when you type "cmd" in the start menu) and change the start directory there.

For me, the shortcut was located in:

C:\Users\<username>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\System Tools

Right click the cmd shortcut, select properties, and modify the start in directory to be whatever you like. Now, when you start a command prompt from the start menu (as I often do) it will have the directory you want.

0

I may be few years too late but Why to make things far too complicated just to run cmd as admin in specific folder.

Create a shortcut.

copy this to target folder

%windir%\system32\cmd.exe /k " cd\ & cd c:\YOURdirectory

if located in different drive other than c: then do this

%windir%\system32\cmd.exe /k " cd\ & YOURdrive: & cd YOURdrive:\YOURdirectory

copy this to start in

%homedrive%%homepath%

on advanced properties choose to run shortcut as admin.

0
0

As a better and more flexible option you can use Autohotkey to create keyboard shortcuts to switch between directories in cmd. E.g. using the script shown below you can switch to any directory (bound to Ctrl+F12 combo). It just sends the same commands which you would type in the cmd prompt.

#If winActive("ahk_exe cmd.exe") 

^F12::
    send {text}cd /d d:\mydir\mysubdir\
    send {enter}
return

With this approach you don't need to create multiple shortcuts for the executable and can add other useful commands for navigating, etc.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .