Open CMD prompt as Administrator to any folder?
Moderators: fgagnon, nikos, Site Mods
-
appyface
- Silver Member

- Posts: 260
- Joined: 2005 Jun 11, 16:48
Open CMD prompt as Administrator to any folder?
Does x2 offer any way to open a CMD window prompt as Administrator, for the folder I'm currently browsing, with just a few clicks?
I can access Windows Explorer shortcuts from x2, but powershell terminal is my default and I don't want to change that, so CMD isn't offered.
I know of several roundabout ways to accomplish this, but none are few clicks solutions. Any help from x2 by any chance?
I can access Windows Explorer shortcuts from x2, but powershell terminal is my default and I don't want to change that, so CMD isn't offered.
I know of several roundabout ways to accomplish this, but none are few clicks solutions. Any help from x2 by any chance?
-
appyface
- Silver Member

- Posts: 260
- Joined: 2005 Jun 11, 16:48
Re: Open CMD prompt as Administrator to any folder?
Just to clarify: The closest workaround I have is a registry hack to add 'open cmd as admin' shortcut to explorer menu. That does show up on x2's explorer menu shortcuts. Win11 update breaks that hack fairly often for some reason, I have to recreate it and reboot.
Hence question to ask if there's a way x2 itself can offer this.
Hence question to ask if there's a way x2 itself can offer this.
-
Kilmatead
- Platinum Member

- Posts: 4842
- Joined: 2008 Sep 30, 06:52
- Location: Baile Átha Cliath
Re: Open CMD prompt as Administrator to any folder?
Doesn't Window -> Administrator open an elevated x2 instance? At which point if you really do still want a console window (if the elevated instance isn't sufficient by itself), just typing > cmd into the addressbar (or keeping one as a user-command) will open a console to the current active folder. (For those using the dreaded Ribbon, the Admin command is under Workbench, apparently.)
(To be honest, speaking as a user who has never run as anything but admin, I don't know if Window -> Admin actually clones the current settings or not, since mine is eternally greyed out I can't test it, but cloning would seem a logical expectation, in which case your current folder would be preserved.)
(To be honest, speaking as a user who has never run as anything but admin, I don't know if Window -> Admin actually clones the current settings or not, since mine is eternally greyed out I can't test it, but cloning would seem a logical expectation, in which case your current folder would be preserved.)
-
appyface
- Silver Member

- Posts: 260
- Joined: 2005 Jun 11, 16:48
Re: Open CMD prompt as Administrator to any folder?
I do want a CMD prompt window, not administrator mode in x2, but good question.
When I type CMD and press ENTER in the address bar in windows explorer (overtyping the path), that opens a tabbed CMD prompt window but not elevated. (N.B. It is a different looking window than what I use, which isn't tabbed and has a colored titlebar. TBH I have not investigated if they are the same in function.) Anyway, at one time using SHIFT-CTRL-ENTER instead of just ENTER would open an elevated version but no more (I'm using Win11 Pro).
On x2's addressbar, unlike Windows Explorer, if I overtype the path with CMD and press ENTER, I get "The CPU cannot make sense of the last input" error message. Is there somewhere else this should be done? And can it be made to bring up an elevated prompt other than first opening x2 in administrator mode?
When I type CMD and press ENTER in the address bar in windows explorer (overtyping the path), that opens a tabbed CMD prompt window but not elevated. (N.B. It is a different looking window than what I use, which isn't tabbed and has a colored titlebar. TBH I have not investigated if they are the same in function.) Anyway, at one time using SHIFT-CTRL-ENTER instead of just ENTER would open an elevated version but no more (I'm using Win11 Pro).
On x2's addressbar, unlike Windows Explorer, if I overtype the path with CMD and press ENTER, I get "The CPU cannot make sense of the last input" error message. Is there somewhere else this should be done? And can it be made to bring up an elevated prompt other than first opening x2 in administrator mode?
-
Kilmatead
- Platinum Member

- Posts: 4842
- Joined: 2008 Sep 30, 06:52
- Location: Baile Átha Cliath
Re: Open CMD prompt as Administrator to any folder?
It needs to be prefixed with a ">", literally typed as > cmd, not just "cmd".appyface wrote: 2025 Nov 22, 18:54 On x2's addressbar, unlike Windows Explorer, if I overtype the path with CMD and press ENTER, I get "The CPU cannot make sense of the last input" error message.
A quick perusal of these things suggests you could also use "runas /user:Administrator cmd" from within a normal cmd prompt to issue an elevated one (this seems to use the default Admin account, if you have a different one already set up, use that name instead), but it does not appear to preserve the current folder, so other means might be more appropriate.
I imagined the "Windows -> Admin" thing as something to use as a quick once-off, then closed back to the previous instance, but like I said, never having used it, I can't say. It is overkill just for a prompt though.
-
appyface
- Silver Member

- Posts: 260
- Joined: 2005 Jun 11, 16:48
Re: Open CMD prompt as Administrator to any folder?
Ah, so sorry, I thought that > was just an "arrow" to point out the command "CMD".
That does work the same as windows explorer, opens the tabbed instance format that isn't elevated. From there I tried using the runas command but need to look up the syntax, just guessing for the userid I want (not default Administrator) didn't work. I also need to see if the tabbed version works the same as the window I'm used to using.
I just put the registry hack back for now, is still the easiest - until it breaks (again).
Thanks for all the ideas.
That does work the same as windows explorer, opens the tabbed instance format that isn't elevated. From there I tried using the runas command but need to look up the syntax, just guessing for the userid I want (not default Administrator) didn't work. I also need to see if the tabbed version works the same as the window I'm used to using.
I just put the registry hack back for now, is still the easiest - until it breaks (again).
Thanks for all the ideas.
-
Kilmatead
- Platinum Member

- Posts: 4842
- Joined: 2008 Sep 30, 06:52
- Location: Baile Átha Cliath
Re: Open CMD prompt as Administrator to any folder?
Yeah, it uses the "hidden" admin account, but I think that needs to be exposed first using "net user administrator /active:yes" but that's carrying things a bit too far for an otherwise simple request. Plus, as I said, it doesn't inherit the current path (and can't seem to be forced to), so it fails the primary criterion anyway.appyface wrote: 2025 Nov 22, 19:48 but need to look up the syntax, just guessing for the userid I want (not default Administrator) didn't work.
The cmd prompt launched from a "temporary" instance of Window -> Admin would, at least, persist after the instance was immediately closed, but that's still just a long-winded workaround.
-
appyface
- Silver Member

- Posts: 260
- Joined: 2005 Jun 11, 16:48
Re: Open CMD prompt as Administrator to any folder?
I do have the "hidden" administrator account exposed with that comand. I don't want that for the CMD prompt window, I want my own userid. I failed to guess the syntax for the runas. It's OK, I'll look up the syntax later just for my own edification. As you stated, that one doesn't know the current directory which defeats the entire goal anyway so not worth pursuing.
Maybe Nikos will add CMD to x2 to open in current userid and current directory, elevated?
Maybe Nikos will add CMD to x2 to open in current userid and current directory, elevated?
-
Kilmatead
- Platinum Member

- Posts: 4842
- Joined: 2008 Sep 30, 06:52
- Location: Baile Átha Cliath
Re: Open CMD prompt as Administrator to any folder?
As an experiment, try typing (pasting?)
into the addressbar and see what happens? That does seem to elevate cmd whilst auto-preserving the current path. If it works, you could just make a toolbar button out of a user-command for it. (Assuming it doesn't result in any weird UAC dialogue z-order issues...)
Code: Select all
> powershell -Command "Start-Process cmd -Verb RunAs"-
appyface
- Silver Member

- Posts: 260
- Joined: 2005 Jun 11, 16:48
Re: Open CMD prompt as Administrator to any folder?
You're trying to trip me up with your > character again
(Had to remove it from your code for powershell command)
That code opened an Administrator CMD prompt window in the format I am used to (no tabs, colored titlebar). Yay.
I tried two ways: 1) Launched powershell from start menu, which opened initially onto c:\WINDOWS\system32, then changed to a different drive/directory within powershell terminal, and 2) Launched powershell from windows explorer shortcut menu, which opened onto same drive/directory being browsed from windows explorer.
In both cases the CMD prompt window directory is c:\WINDOWS\system32, the launch of CMD did not pick up my current drive/directory
That code opened an Administrator CMD prompt window in the format I am used to (no tabs, colored titlebar). Yay.
I tried two ways: 1) Launched powershell from start menu, which opened initially onto c:\WINDOWS\system32, then changed to a different drive/directory within powershell terminal, and 2) Launched powershell from windows explorer shortcut menu, which opened onto same drive/directory being browsed from windows explorer.
In both cases the CMD prompt window directory is c:\WINDOWS\system32, the launch of CMD did not pick up my current drive/directory
-
Kilmatead
- Platinum Member

- Posts: 4842
- Joined: 2008 Sep 30, 06:52
- Location: Baile Átha Cliath
Re: Open CMD prompt as Administrator to any folder?
There are command line switches (/K, etc) for launching cmd with a command execute like "cd $P", but passing them through the PS shell just causes it to short-circuit (it doesn't seem to nest-quotation-marks), so it might be syntactical or require a self-contained batch script of some sort.
Where's a powershell guru when you need one...
-
nikos
- Site Admin

- Posts: 16341
- Joined: 2002 Feb 07, 15:57
- Location: UK
Re: Open CMD prompt as Administrator to any folder?
chatgpt claims that this powershell can do it
after /d you would put $P to get the current xplorer2 folder for the user command
Code: Select all
runas /user:Administrator "cmd.exe /k cd /d C:\MyFolder"