Start elevated command prompt in %UserProfile% directory by default?

Posted on

Problem :

When I start an elevated Command Prompt in Windows 7 or Windows Vista, the initial directory is the %SystemRoot%system32 directory.

This is the default Windows behavior, and is not a problem specific to my system, so I’m not expecting some sort of “bug fix” here, but rather a tweak to “fix” the default behavior.

To repro:

  • Click Start
  • Type cmd.exe
  • Hit Ctrl+Shift+Enter
  • When the elevation prompt appears, select Yes


  • The initial directory is my user profile directory, e.g. C:Usersmerlyn


  • The initial directory is the system32 directory, C:Windowssystem32

I’d like this be easy to work with. I’d like it to apply to all cmd.exe prompts/shortcuts, regardless of where they’re started from. E.g. I’d like it to automatically apply to my Visual Studio Command Prompt (2010) without having to modify that specific shortcut.

I’d like this to be safe so that batch files aren’t broken by my fixes.

Is there an easy and safe way to get any elevated command prompt to start in the %UserProfile% directory by default?

Solution :

Opening an elevated command-prompt always starts in %systemroot%System32, the rationale being that if you are doing something requiring elevated privileges, you are likely to be working on system files as opposed to just the user’s own files which you can do without elevated privileges.

You can work around it:

  1. Open a registry editor (e.g., regedit)
  2. Navigate to HKEY_CURRENT_USERSoftwareMicrosoftCommand Processor
  3. Edit the Autorun value to read cd /d %userprofile%

Now whenever you open a command-prompt, it will either start in or switch to, as the case may be, the user profile directory. Also, instead of HKCU, you can set the value in the HKLM branch to do it for all users on the system.

Assuming your merlyn login has administrative rights, it doesn’t actaully have those rights untill the UAC prompt has been processed. These rights come with requsting the elevated rights and recieving them when the prompt has been correctly passed. Under the elevated token it is running in a different security context than the standard level of your account pre UAC authorized. All this means that your expected outcome is false, and the actual outcome is actually the expected.

Understanding and Configuring User Account Control

Leave a Reply

Your email address will not be published. Required fields are marked *