It’s too difficult to set the default command prompt directory on Windows. I found several methods, none of which worked correctly.
In particular, it is common for people to set a “cd /d path” in their AutoRun key in the registry but this breaks the power toy and Windows 7’s built in hold shift and right click on a directory to open a command prompt there. This can be worked around by adding a /d to the shell extension in the registry.
What doesn’t seem to be mentioned anywhere though is that this AutoRun key also gets run when you double click on a batch file. That means a batch file which assumes its own current directory (a reasonable assumption – more reasonable than using absolute paths) may not be able to find files in the same directory as it.
What I really wanted to do was move my home directory to my D: drive but the command prompt was still opening on the C:
Most people also seem to only change the default directory of their command prompt to match a non-default home directory.
The first mistake I made was to type “cmd” into the start menu and right click on it to pin it there. This calls it “Windows Command Processor” and starts in C:\Windows\System32 (because that’s where cmd.exe lives). Instead, go through the start menu programs list and find “Command Prompt” under “Accessories” and pin that. It will correctly default to your home directory, because the “start in” is set to
%HOMEDRIVE%%HOMEPATH%. Note that you could just change this shortcut’s arguments (cmd /k cd “PATH”) or start in but it will only change it for that one shortcut.
Anyway, once you are using “Command Prompt”, set your home directory. I’m using Windows 7 Pro, so I can go to Computer Management and just set the directory for my user in the GUI under “Users and Groups”. This is no longer available in home versions of Windows (they shouldn’t have removed it) but you may still be able to set your home directory by using the command
net user USERNAME /homedir:PATH
where “USERNAME” is your user name and “PATH” is the directory you want to set. You can check this with the command
When I type “cmd” into the run dialogue, it still opens on C: but at least batch files work now. Further suggestions are welcome.