7
1
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
Expected:
- The initial directory is my user profile directory, e.g.
C:\Users\merlyn
Actual:
- The initial directory is the system32 directory,
C:\Windows\system32
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?
Setting the initial working directory via autorun can cause problems with some scripts. See my comment on your other similar answer.
– rojo – 2015-08-29T04:38:37.570The key was not present on my system, but I added it as a string (REG_SZ) and it worked immediately from windows key-X A – Wyrmwood – 2017-10-26T15:37:49.167
Thanks, I'll give this a shot! Just a comment: If this is true, seems like lame rationale to me :) The only file I routinely edit with elevated privileges is under
system32
is the hosts file. The rest of them are almost always under%ProgramFiles%
/%ProgramFiles(x86)%
, a custom directory in the root, or a file for a different account underC:\Users
. – Merlyn Morgan-Graham – 2012-03-13T02:46:15.203There’s no way to know why you are opening an elevated command-prompt, so it just uses System32 as a reasonable default. – Synetech – 2012-03-13T02:48:17.917
I was going to reply to this with a rebuttal. But I realized it is both idle speculation, and quite OT, so I'll just drop it :) Again thanks for your help. I'll accept for now, and reply later if I find anything gets broken by this fix. – Merlyn Morgan-Graham – 2012-03-13T02:55:25.067
Well you said that you are opening the command-prompt via
– Synetech – 2012-03-13T03:43:07.207cmd
. In that case, Windows has no idea what your intention is (maybe the PS9 can read your mind, but Windows cannot). If you want to open a command prompt to a specific location, you can use a shell-extension such as Kai Liu’s which allows you to open a regular or elevated command-prompt at that folder.Alright. Since you continued the thread... lol. Windows never has any idea of my intent when launching cmd.exe, and this doesn't change depending whether or not I have elevated. There was already a default, and there is no compelling reason to change it, as there is no new info provided. I speculate (since I didn't work on the team that implemented UAC or patched cmd.exe after UAC was added) that this is just a quirk of cmd.exe, and that this whole "change" in behavior wasn't intentional. It is probably just a by-product of the multiple-token thing, and the order in which system calls are made – Merlyn Morgan-Graham – 2012-03-13T04:15:06.823
Then again, the whole DOS system is full of poor design decisions and lack of fixes for backwards-compatibility reasons, so I guess I wouldn't put it past them to intentionally have made a bad call here :) Okay, rant over! – Merlyn Morgan-Graham – 2012-03-13T04:18:21.500
You’ve already said yourself that it has access to the same environment variables and data. It’s a simple matter that it makes no sense to be opening an elevated prompt in your own home directory because you don’t need elevated privileges to work in there. – Synetech – 2012-03-13T04:21:06.630