How to open Command Prompt in a specific folder as Administrator?
I made a shortcut to cmd.exe and specified the folder that I want to start in. I then went to Advanced and ticked Run as administrator.
When I double-click on the shortcut, it always starts in C:\Windows\System32
.
What I am missing? How can I get the command line to start in the folder specified?
Solution 1:
In the target you should specify cmd /k cd c:\crp
Solution 2:
If you want the reasoning behind it, the Start in
is explicitly ignored when elevation is performed (only on binaries that are part of Windows itself) to protect against a potential security vulnerability.
The basic idea is that potentially-malicious DLLs located in the working directory might be controlled by a user other than the current admin, and can then be loaded with high privileges. To prevent this, UAC will reset the working directory. Because shortcuts' "Start in" is set before elevation occurs, this gets reset during elevation. In an ideal world, this protection would apply to all elevations, but it only applies to built-in Windows binaries because it breaks some third-party programs that expect the working directory to be preserved.
The other answers bypass this by telling the elevated cmd
to change its working directory after elevation occurs, via the /k
argument.