6

I am running Windows 7 and when I run cmd.exe I want it to start up in a directory named C:\foo\bar. I remember being able to create a link to this executable on the desktop and right clicking somewhere to set the startup menu of the cmd.exe command prompt by filling out a field in a transient window, but I cannot find it. I have found the following argument which however seems more complicated. I want to set the startup directory for cmd.exe via a popup window.

Changing default startup directory for command prompt in Windows 7

Any ideas?

Community
  • 1
  • 1
John Goche
  • 689
  • 2
  • 12
  • 27

4 Answers4

17

as mentioned by the other posters already: the regular approach is to edit the shortcut's properties and fill the field labled "start in". simple as that.

however, for some reason this has no effect on UAC enabled systems if at the same time you also enable the "run as administrator" checkbox in the advanced properties of the shortcut.

enter image description here

a solution is to put everything in the "target" field of the shortcut:

%windir%\System32\cmd.exe /K cd /d "E:\My Folder" & sometest.bat

when running on 64bit and you want to explicitly start the 32bit flavour of the command prompt:

%windir%\SysWOW64\cmd.exe /K cd /d "E:\My Folder" & sometest.bat



for additional information on the command line parameters used above see:
cmd.exe /?
cd.exe /?

Opmet
  • 1,754
  • 18
  • 20
  • What is the `/d` switch doing? – rstackhouse Jul 02 '13 at 22:06
  • 2
    /d tells cd to use the full path and change drive letters as needed. So instead of doing something like "prompt> d:" to get to the D drive and then doing "prompt> cd somedir_on_d" you can just "cd /d d:\somedir_on_d"...really handy once you know it's there. – Milner Oct 30 '13 at 19:06
  • Thanks, exactly what I need! This should be the chosen answer! – Doan Van Tuan Mar 21 '14 at 08:12
  • 2
    The *reason* it doesn't work is `Start in` merely sets the working directory, but UAC does not inherit working directly specifically to prevent attacks on the search path (note that `sudo` does the same thing by default on *nix). – Bob Dec 25 '14 at 21:13
  • How do I execute another command after `/K cd /d "E:\My Folder" ` ? Such as I want to start at some place and enter a python virtualenv, which need extra command `activate py3` – Mithril Dec 25 '17 at 02:32
7

When you create a shortcut to cmd.exe, you can open the shortcut properties and find under Shortcut tab the Starts in option that will tell cmd.exe where to start, like here:

Command Prompt Shortcut Properties

Luis Lavena
  • 10,348
  • 1
  • 37
  • 39
4

Open the properties of a shortcut to cmd and set the directory there:

enter image description here

Joey
  • 344,408
  • 85
  • 689
  • 683
0

Try this Shortcut Target:

C:\Windows\System32\cmd.exe cd /d %~dp0

Which will start cmd.exe in the shortcut's folder.

Dale K
  • 25,246
  • 15
  • 42
  • 71