22

I want to change the CMD startup directory when I launch it via Start+R

Currently, it points to my users folder. I need it to point to C:\Windows\System32\

When I navigate using explorer to C:\Windows\System32\ and run CMD from there (Shift+RightClick on an empty area), it starts in the desired path. When I run from Win+R, it starts from the users folder.

I suspect I need to change the registry or an environment variable. Anyone knows how to ?

THIS QUESTION IS DIFFERENT FROM THE OTHERS FOR THE REASON EXPLAINED BY @KARAN (READ THE THIRD COMMENT FROM THE ANSWERS BELOW)

DIFFERENT ANSWERS ONLY WORK FOR SHORTCUTS

Edit: Found the right answer hidden on the pit of the provided links, kilometers away from the supposed "right answer"

[HKEY_CURRENT_USER\Software\Microsoft\Command Processor] "Autorun"="cd C:\Windows\System32\"

Lucas BS
  • 482
  • 1
  • 3
  • 18
  • 2
    possible duplicate of [How can I update the default directory for Windows Command Processor to be my home directory?](http://superuser.com/questions/611853/how-can-i-update-the-default-directory-for-windows-command-processor-to-be-my-ho), [Windows 7 Administrator Command Prompt “Start in” Path](http://superuser.com/questions/87398/windows-7-administrator-command-prompt-start-in-path) – Ƭᴇcʜιᴇ007 May 18 '15 at 00:45
  • It's just a workaround :) Autorun holds any command to execute when the process (`cmd.exe`) is started. It won't work in many cases such as if `%homedrive%` is not `c:` as `cd` would require `/d` switch to change into another drive, or `%windir%` is not `c:\windows` :) –  May 18 '15 at 22:04
  • It won't work if *AutoRun* is disabled by `cmd /d` :) –  May 18 '15 at 22:12
  • 2
    Alternatively you may use `cmd /k "cd /d %windir%\sytstem32"` for the same purpose. –  May 18 '15 at 22:15
  • https://superuser.com/questions/49575/change-to-default-start-folder-for-windows-xp-command-prompt/49590#49590 – Ƭᴇcʜιᴇ007 Mar 10 '17 at 14:37
  • Why do you need it to open in system32? That's what mine always does by default. It never opens where I want it. Ah - Chinggis6 solved it for me. A great answer in comments. – SDsolar Apr 23 '18 at 19:25
  • The greatest problem with usage of `Autorun` registry value is that the command line specified there is executed every time `cmd.exe` is started by __any application__. `cmd.exe` starts `cmd.exe` on running a `for /F` loop with a command line enclosed in `'`. Many applications start `cmd.exe` as it is the default shell processor on Windows via the environment variable `ComSpec`. The usage of ``cd C:\Windows\System32\`` will cause lots of troubles as most applications running `cmd.exe` in background expect that the current directory of the process is also the current directory for `cmd`. – Mofi Sep 28 '20 at 16:52
  • Run in a command prompt window following command line: `cd /D %SystemRoot% & for /F "eol=| delims=" %I in ('dir *.exe /A-D /B') do @if not exist "%~fI" echo Missing file: "%~fI"` It can be seen that `dir` does not output the .exe files in directory `C:\Windows` which is the current directory after `cd /D %SystemRoot%`, but the file names of all .exe files in `%SystemRoot%\System32`. The current cmd process searches because of `%~fI` for the executable in `%SystemRoot%`, can't find it there, concatenates therefore ``C:\Windows`` with the file name output by `dir` and `if` can't find the files. – Mofi Sep 28 '20 at 17:01
  • The real solution is creating a shortcut file (.lnk file) on Windows desktop or somewhere in Windows start menu and define in properties of the shortcut file as __Target__ the command line `%ComSpec%` or `%SystemRoot%\System32\cmd.exe`, define as __Start in__ the directory path `%SystemRoot%\System32` and define also a __Shortcut key__ for this shortcut file. Then a command prompt window can be opened from within any running application by pressing the defined shortcut key and `cmd` is started with `C:\Windows\System32` as current directory. – Mofi Sep 28 '20 at 17:06
  • The Windows start menu contains already a shortcut file to open a command prompt window in __Accessories__. Therefore it is enough to change in properties of this shortcut file the __Start in__ directory and the __Shortcut key__ for launching it by key from anywhere at any time. It is unbelievable for me that this question with the edit got 17 upvotes although the "solution" corrupts the `cmd` execution environment. – Mofi Sep 28 '20 at 17:08

1 Answers1

14

If you hit the Win (Start) button and type CMD search field, instead of clicking Command Prompt (cmd.exe or Command Prompt depending on Windows version), either right click and choose properties, or if not present, choose Open File Location then right click and choose properties of the CommandPrompt shortcut.

You can get to it directly in this folder: %APPDATA%\Microsoft\Windows\Start Menu\Programs\System Tools

In the "Start in:" field, it normally says %HOMEDRIVE%%HOMEPATH%

This makes cmd start in the home folder. You can change this to be whatever you'd prefer.

Paul
  • 59,223
  • 18
  • 147
  • 168
  • Win+R (which is what I suppose he means by Start+R) is the Run dialog, and you're confusing it with searching in the Start Menu for the Command Prompt shortcut. If he opens a command prompt window by typing cmd in the Run dialog, what you've suggested obviously won't work for him. – Karan May 18 '15 at 00:57
  • 1
    @Karan I am interpreting what the OP wrote as using Start+R (Win+R) and typing `cmd` - so unless my interpretation is incorrect, then this answer will work for him (try it). In any case, it is a dupe by the look of it, I should have checked. – Paul May 18 '15 at 01:08
  • You're asking me to try it? Please try it yourself. Go ahead: press Win+R, type cmd in the text field, right-click it and now where do you see Properties? Let me repeat, you've confused typing cmd in the Run dialog (Win+R) with searching for the Command Prompt shortcut in the Start Menu (Win). Only the *shortcut* has a Properties dialog you can edit. – Karan May 18 '15 at 01:12
  • @Karan Crap, sorry, you are right, I instinctively hit the win button and typed it, missed what you were saying. – Paul May 18 '15 at 01:16
  • dont see properties in windows 10 – Kalpesh Soni Jun 12 '18 at 18:44
  • 1
    @KalpeshSoni Answer updated to reflect more recent versions. – Paul Jun 12 '18 at 22:16
  • It's weird that this does not affect the startup directory when using command prompt with Windows Terminal. – kakyo Jun 24 '21 at 07:29