toolbar button for "open cmd as admin"

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
jerrygoyal
Posts: 1
Joined: 17 Feb 2017 15:48

toolbar button for "open cmd as admin"

Post by jerrygoyal »

There's a toolbar button for cmd but not for "cmd as admin". Is there any way to open cmd as admin?

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

Re: toolbar button for "open cmd as admin"

Post by highend »

Scripting is (probably) always a solution (Pro version required).

A very old script that I can put on a toolbar button:

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") { // Left click -> Admin
        run """$cscript"" ""$vbsFile"" //nologo", , 0, 0;
    } elseif (get("trigger") == "2") { // Right click -> No admin
        run """$comspec"" /k pushd ""<curpath>""";
    }
On left click it starts the cmd with admin permissions and on right click without...
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60598
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: toolbar button for "open cmd as admin"

Post by admin »

I tried to do this right in the code and it works. I get a box that looks e.g. like this. On demand I could make this available as Miscellaneous function.
Attachments
AdminBox.png
AdminBox.png (3.37 KiB) Viewed 2691 times

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

Re: toolbar button for "open cmd as admin"

Post by highend »

As long as it is the 64-bit cmd prompt on a 64-bit system, it's fine :)
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60598
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: toolbar button for "open cmd as admin"

Post by admin »

highend wrote:As long as it is the 64-bit cmd prompt on a 64-bit system, it's fine :)
Acc. to Task Manager it is the 64-bit cmd prompt.

JLoftus
Posts: 579
Joined: 22 Jan 2014 14:58

Re: toolbar button for "open cmd as admin"

Post by JLoftus »

+1 for supporting this. Thanks Don... and THIS is why the Slant poll continues to show XY as the leader: Direct and immediate responses from the Developer! You sir, are gentleman among thieves (and when comparing to DO, that's never been more appropriate!). :beer:

admin
Site Admin
Posts: 60598
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: toolbar button for "open cmd as admin"

Post by admin »

I decided to handle this with a new scripting command: opencommandprompt.

Piece of cake to create a button for it then.

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

Re: toolbar button for "open cmd as admin"

Post by highend »

Code: Select all

opencommandprompt , , , 1;
Should start an elevated command prompt for the current directory.
But nothing happens. Literally nothing.

Code: Select all

opencommandprompt "C:\", 3:=1;
Same. It seems once the 4th the elevate flag is set the command refuses to do something...
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60598
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: toolbar button for "open cmd as admin"

Post by admin »

Oha!? Both works fine here. Win 8.1

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

Re: toolbar button for "open cmd as admin"

Post by highend »

Win 7 x64 in an older notebook here. Don't have access to my other systems currently...
One of my scripts helped you out? Please donate via Paypal

PeterH
Posts: 2785
Joined: 21 Nov 2005 20:39
Location: Germany

Re: toolbar button for "open cmd as admin"

Post by PeterH »

To verify I've just tested both forms in W7pro X64: both work just as expected.
Win11 Pro 223H2 Gerrman

klownboy
Posts: 4141
Joined: 28 Feb 2012 19:27

Re: toolbar button for "open cmd as admin"

Post by klownboy »

Both prompts work in Windows 10 x64 .
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

JLoftus
Posts: 579
Joined: 22 Jan 2014 14:58

Re: toolbar button for "open cmd as admin"

Post by JLoftus »

Running version 17.50.0210, if I create a CTB with opencommandprompt; I am getting:
'opencommandprompt' is not a valid script command.

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

Re: toolbar button for "open cmd as admin"

Post by highend »

You need 219^^
One of my scripts helped you out? Please donate via Paypal

JLoftus
Posts: 579
Joined: 22 Jan 2014 14:58

Re: toolbar button for "open cmd as admin"

Post by JLoftus »

Got 222, now working great, thanks!

Post Reply