Open CMD prompt as Administrator to any folder?

Discussion & Support for xplorer² professional

Moderators: fgagnon, nikos, Site Mods

appyface
Silver Member
Silver Member
Posts: 260
Joined: 2005 Jun 11, 16:48

Open CMD prompt as Administrator to any folder?

Post by appyface »

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?
appyface
Silver Member
Silver Member
Posts: 260
Joined: 2005 Jun 11, 16:48

Re: Open CMD prompt as Administrator to any folder?

Post by appyface »

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.
Kilmatead
Platinum Member
Platinum Member
Posts: 4842
Joined: 2008 Sep 30, 06:52
Location: Baile Átha Cliath

Re: Open CMD prompt as Administrator to any folder?

Post by Kilmatead »

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.)
appyface
Silver Member
Silver Member
Posts: 260
Joined: 2005 Jun 11, 16:48

Re: Open CMD prompt as Administrator to any folder?

Post by appyface »

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?
Kilmatead
Platinum Member
Platinum Member
Posts: 4842
Joined: 2008 Sep 30, 06:52
Location: Baile Átha Cliath

Re: Open CMD prompt as Administrator to any folder?

Post by Kilmatead »

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.
It needs to be prefixed with a ">", literally typed as > cmd, not just "cmd".

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
Silver Member
Posts: 260
Joined: 2005 Jun 11, 16:48

Re: Open CMD prompt as Administrator to any folder?

Post by appyface »

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.
Kilmatead
Platinum Member
Platinum Member
Posts: 4842
Joined: 2008 Sep 30, 06:52
Location: Baile Átha Cliath

Re: Open CMD prompt as Administrator to any folder?

Post by Kilmatead »

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.
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.

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
Silver Member
Posts: 260
Joined: 2005 Jun 11, 16:48

Re: Open CMD prompt as Administrator to any folder?

Post by appyface »

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? :D
Kilmatead
Platinum Member
Platinum Member
Posts: 4842
Joined: 2008 Sep 30, 06:52
Location: Baile Átha Cliath

Re: Open CMD prompt as Administrator to any folder?

Post by Kilmatead »

As an experiment, try typing (pasting?)

Code: Select all

> powershell -Command "Start-Process cmd -Verb RunAs"
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...)
appyface
Silver Member
Silver Member
Posts: 260
Joined: 2005 Jun 11, 16:48

Re: Open CMD prompt as Administrator to any folder?

Post by appyface »

You're trying to trip me up with your > character again :D (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 :(
Kilmatead
Platinum Member
Platinum Member
Posts: 4842
Joined: 2008 Sep 30, 06:52
Location: Baile Átha Cliath

Re: Open CMD prompt as Administrator to any folder?

Post by Kilmatead »

:( In that case I'm out of ideas... on my system (Win10) it certainly requires the ">" to execute and also carries over the path by itself, so I can't explain it.

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...
User avatar
nikos
Site Admin
Site Admin
Posts: 16341
Joined: 2002 Feb 07, 15:57
Location: UK

Re: Open CMD prompt as Administrator to any folder?

Post by nikos »

chatgpt claims that this powershell can do it

Code: Select all

runas /user:Administrator "cmd.exe /k cd /d C:\MyFolder"
after /d you would put $P to get the current xplorer2 folder for the user command