Set the default working directory for a command prompt.

Technical Q&A involving operating systems, networking, software, and hardware issues.

Moderator: jasonb

Post Reply
User avatar
jasonb
Site Administrator
Posts: 105
Joined: Tue Apr 22, 2003 1:54 pm
Location: Toronto, Canada
Contact:

Set the default working directory for a command prompt.

Post by jasonb »

1. Run regedit and navigate to HKEY_CURRENT_USER \ Software \ Microsoft \ Command Processor.
2. Add the string "Autorun" and give it the value "cd /d C:\Directory" (replace this with the actual path).
User avatar
jasonb
Site Administrator
Posts: 105
Joined: Tue Apr 22, 2003 1:54 pm
Location: Toronto, Canada
Contact:

Re: Set the default working directory for a command prompt.

Post by jasonb »

A side effect of this is batch files. If you've set a default working directory for cmd.exe, batch files will use that as their working directory, rather than the directory where the batch file is located. To override this in the case of a particular batch file, add the following command at the top:

cd /d "%~dp0"

This changes directories to the location of the batch file itself - which is its first called parameter.
Post Reply