Elevated Command Prompt Option?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Jeff Bellune
Posts: 284
Joined: 13 Dec 2007 12:55

Elevated Command Prompt Option?

Post by Jeff Bellune »

Is there a non-scripted, easily-accessible way to make the Command Prompt Toolbar Button open an elevated command prompt? If not, can I make a wish? :)

Cheers,
Jeff

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Elevated Command Prompt Option?

Post by bdeshi »

Nope.


====
You can just replace the default cmd toolbar button with a custom button that runs an elevated cmdprompt. That's hardly scripting
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Jeff Bellune
Posts: 284
Joined: 13 Dec 2007 12:55

Re: Elevated Command Prompt Option?

Post by Jeff Bellune »

SammaySarkar wrote:You can just replace the default cmd toolbar button with a custom button that runs an elevated cmdprompt. That's hardly scripting
Well that's the rub, isn't it? Over an hour and a half searching this forum, the help files and Google and I can't find a way to edit a custom button to open an elevated command prompt. If you know how, would you mind sharing? Thanks!

Jeff

highend
Posts: 14993
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Elevated Command Prompt Option?

Post by highend »

Add a custom button.
Right click on it, "Edit..."

Name: "CMD"
Icon: ":dosbox"
On left click: "Edit..."
On right click: "Edit..."

For name & icon: Don't enter the quotation marks!
For left & right click and pressing "Edit..." - Enter this script:

Code: Select all

    $comspec = ("%osbitness%" == 64) ? "%windir%\System32\cmd.exe" : "%windir%\SysWoW64\cmd.exe";
    $cscript = ("%osbitness%" == 64) ? "%windir%\System32\cscript.exe" : "%windir%\SysWoW64\cscript.exe";

    $vbsFile = "%TEMP%\~OpenElevatedCMD.vbs";

    $vbsContent = <<<>>>
        Set UAC = CreateObject("Shell.Application")
        UAC.ShellExecute "$comspec", "/k pushd ""<curpath>""", "", "runas", 1
>>>;

    writefile($vbsFile, trim($vbsContent));

    if (get("trigger") == "1") { // LeftClick
        run """$comspec"" /k pushd ""<curpath>""";
    } elseif (get("trigger") == "2") { // RightClick
        run """$cscript"" ""$vbsFile"" //nologo", , 0, 0;
    }
Left clicking on the button will start a normal CMD in the current folder
Right clicking on it will start an elevated CMD in the current folder...
One of my scripts helped you out? Please donate via Paypal

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Elevated Command Prompt Option?

Post by bdeshi »

Great!
I was just about to post the almost an exact duplicate of highend's rclick script! :o (basically)

edit: here's my version, it just runs the elevated prompt. place this script in the LCLick box.

EDIT-NOTICE: This script always opens the 32bit command prompt on 64 bit OSes, which can be inconvenient for some tasks. (touche, highend! :wink: )
In any case, highend's script above is highly superior in more ways than one, do use that.

Code: Select all

if (exists("<xyscripts>\elevcmd.vbs")!=1){
 writefile("<xyscripts>\elevcmd.vbs",<<<#>>
set oArgs = WScript.Arguments
set oSh = CreateObject("Shell.Application")
oSh.ShellExecute "%COMSPEC%", "/k pushd " & """" & oArgs(0) & """", "", "runas"#>>);}
 run "%WINDIR%\system32\cscript.exe ""<xyscripts>\elevcmd.vbs"" ""<curpath>""",,0,0;
[/size]
edit: hopefully fixed --> elevated prompt wouldn't open if <curpath> had some special characters.
the last edit: hopefully improved --> elevated cmdprompt is 64bits now, depending on "Show real system32 Directory" setting (keep it enabled).
That's it. This puny post will not see any more edits ever. :evil:
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Jeff Bellune
Posts: 284
Joined: 13 Dec 2007 12:55

Re: Elevated Command Prompt Option?

Post by Jeff Bellune »

@ highend:
First and foremost, thank you. I was surprised that such a button was not already built-in to XY, since the standard Command Prompt Here button *is* included.

@ SammaySarkar:
Thank you also for taking the time to write a script for the button. Is it OK if I tease you a bit about your comment, "That's hardly scripting."? :) :D :lol:

@ both of you:
:appl: :appl: :appl:
:beer: :beer: :beer:

Cheers,
Jeff

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Elevated Command Prompt Option?

Post by bdeshi »

:kidding:
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

highend
Posts: 14993
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Elevated Command Prompt Option?

Post by highend »

Be careful, Sammys version will start a 32bit CMD on a 64bit OS xD

This can lead to some trouble e.g. if you use commands that insert a key / value into the registry (because they will be stored in a redirected part)...
One of my scripts helped you out? Please donate via Paypal

Jeff Bellune
Posts: 284
Joined: 13 Dec 2007 12:55

Re: Elevated Command Prompt Option?

Post by Jeff Bellune »

Hmmm.

I'm running 64-bit Windows 8.1. highend's script opens a standard 64-bit command prompt at the current location. Sammay's script opens an elevated 32-bit command prompt at the current location, but only if there are no spaces special characters ampersands or carats in the path name.

I understand the 32-bit vs. 64-bit result, but otherwise I don't understand what happened. I copied both scripts using the "Select All" option from the Code Box. Any ideas?

Thanks,
Jeff
Last edited by Jeff Bellune on 22 Aug 2014 14:32, edited 1 time in total.

highend
Posts: 14993
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Elevated Command Prompt Option?

Post by highend »

You've right clicked my button (to get an elevated 64bit CMD)?
One of my scripts helped you out? Please donate via Paypal

Jeff Bellune
Posts: 284
Joined: 13 Dec 2007 12:55

Re: Elevated Command Prompt Option?

Post by Jeff Bellune »

highend wrote:You've right clicked my button (to get an elevated 64bit CMD)?
No. Because I didn't read all of your instructions carefully enough. :oops: I'm sorry for wasting your time.

I almost never want a standard command prompt. I'm going to try to modify your script to see if I can swap left/right button functionality. Wish me luck. :)

Cheers,
Jeff

Jeff Bellune
Posts: 284
Joined: 13 Dec 2007 12:55

Re: Elevated Command Prompt Option?

Post by Jeff Bellune »

I successfully modified the script. That's about as much scripting skill as I have. :)

Thanks again,
Jeff

Jeff Bellune
Posts: 284
Joined: 13 Dec 2007 12:55

Re: Elevated Command Prompt Option?

Post by Jeff Bellune »

Just thought I'd share the end result. Everything works as expected:
CmdButtonInfoTip.jpg
RightClickCmdButton.jpg
Cheers,
Jeff
To see the attached files, you need to log into the forum.

RalphM
Posts: 2116
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Re: Elevated Command Prompt Option?

Post by RalphM »

I tried to adapt highend's button as well but all I get are 32bit CMD prompts even though I'm on W8.1 64bit and "::text %osbitness%" returns 64?
Ralph :)
(OS: W11 25H2 Home x64 - XY: Current x64 beta - Office 2024 64-bit - Display: 1920x1080 @ 125%)

Jeff Bellune
Posts: 284
Joined: 13 Dec 2007 12:55

Re: Elevated Command Prompt Option?

Post by Jeff Bellune »

Left-clicking highend's button launches a standard 64-bit command prompt. Right-clicking the button allows you to launch an elevated 64-bit command prompt. Is that what happens for you?

Jeff

Post Reply