New
#100
Open command window here as administrator - Add in Windows 10
Attachment 320066If you, like me, prefer to 'Shift+Open here' the command window as an administrator without getting greeted by the UAC prompt, then this might be for you. I also got annoyed by the little stroboscopic side effect resulting from how cmd /c start is used in various tutorials so, I went ahead and decided to apply old medicine─nothing too complicated.
I included a README.txt file in the zip and added some additional brief comments in each file about how to set this all up right. At first I was going to write up a full-blown tutorial, but then I got lazy and bored so, please feel free to reply with your suggestions like possible improvements, questions, or other related remarks.
Changelog:
- The .reg file wasn't working properly so it has now been corrected.
- It now also includes the option to add Shift+Open command window here as standard user.
- It now also includes the .reg files needed to remove these added keys from Windows registry.
Hi all,
I just wanted to share an alternative to the current solution (Open Command Prompt Here). This solution will also handle apostrophes or special characters in the target directory. Here's the registry entry:
I think it's much cleaner and less obfuscated compared to the current command:Code:powershell.exe -WindowStyle Hidden -NoProfile -Command "Start-Process -Verb RunAs cmd.exe -ArgumentList \"/k pushd \"\"%V/\"\"\"
All credit goes to mklement0 from this StackOverflow question.Code:cmd /c echo|set/p="%V"|powershell -NoP -W 1 -NonI -NoL "SaPs 'cmd' -Args '/c """cd /d',$([char]34+$Input+[char]34),'^&^& start /b cmd.exe"""' -Verb RunAs"
elecmd3.zip
V3:
- On Windows 11, the command window now correctly reports Windows 11 instead of Windows 10.
- Added UTF-8 support to handle foldernames that contain an apostrophe and/or special characters correctly.
V2:
- The .reg file wasn't working properly so it has now been corrected.
- It now also includes the option to add Shift+Open command window here as standard user.
- It now also includes the .reg files needed to remove these added keys from Windows registry.
@hdmi
Just wanted to give you a heads-up. The Non-UAC version of your script (The one that you need to create a task for) fails when the target directory has a ^ (Caret) or & (Ampersand) anywhere in the path. These need to be escaped somehow. I'm going to give it a shot in a little bit to see if I can get it working.
Also, do you by any chance have a method or command for opening PowerShell 5 as admin?
BTW, I forgot to say it before, but I really appreciate your contributions. The current version of the reg file for this thread is bulletproof and works flawlessly on any directory.
Also, if people want to suppress the window flashing but don't care about the UAC prompt, there is a small tool called RunHiddenConsole that will suppress the window flashing.
The above registry command will completely hide the window flashing. Just make sure RunHiddenConsole is available in the path specified in the command.Code:"C:\Tools\scripts\BIN\RunHiddenConsole.exe" cmd /c echo|set/p="%V"|powershell -NoP -W 1 -NonI -NoL "SaPs 'cmd' -Args '/c """cd /d',$([char]34+$Input+[char]34),'^&^& start /b cmd.exe"""' -Verb RunAs"
Update:
elecmd4.zip
- - - Updated - - -
I do now.
Add Open PowerShell window here as administrator in Windows 10
Hi :)
I recently returned to Windows from macOS and was missing something like this, so here I am.
It works as advertised, but I noticed immediately that the command prompt that opens doesn't open with the style that I've configured for the "normal" system command prompt. That is to say, if I open Command Prompt as Administrator via Win+X or by searching in the Start Menu and opening as Administrator from there, I get my customized command prompt window. It has a semi-translucent red tinted (to warn me that it's running as admin) background, a certain size and scrollback buffer, font, etc.
If I run via this context menu thing, however, it defaults back to the vanilla black background, unconfigured Windowsy command prompt window.
I don't know how Windows stores these profiles - for the non-admin prompts I've configured a bluish tinted background, and it stores these profiles separately and loads them automatically. I did notice, however that when I open the command prompt using this method posted here, the title of the window reads,
whereas on my custom configured command prompt windows opened "normally," it reads,Code:Administrator: C:\Windows\System32\cmd.exe
Does anyone know why this is behaving like it is, if it's related to the title at all, and if there's a way to get these prompts launched from this context menu thing to load the saved profile?Code:Administrator: Command Prompt
Thanks :)
Update:
elecmd5.zip
You're welcome!Thanks :)![]()
Is it possible to run a program directly with cmd from the context menu? I have tried to add
[HKEY_CLASSES_ROOT\*\shell\OpenCmdHereAsAdmin\command] to the script, and tried to add the "%1" variable. But unfortunately it doesnt work