Page 1 of 2
Elevated Command Prompt Option?
Posted: 22 Aug 2014 06:13
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
Re: Elevated Command Prompt Option?
Posted: 22 Aug 2014 06:54
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
Re: Elevated Command Prompt Option?
Posted: 22 Aug 2014 07:59
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
Re: Elevated Command Prompt Option?
Posted: 22 Aug 2014 08:59
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...
Re: Elevated Command Prompt Option?
Posted: 22 Aug 2014 09:22
by bdeshi
Great!
I was just about to post
the almost an exact duplicate of highend's rclick script!

(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!
)
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.

Re: Elevated Command Prompt Option?
Posted: 22 Aug 2014 13:29
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."?
@ both of you:
Cheers,
Jeff
Re: Elevated Command Prompt Option?
Posted: 22 Aug 2014 13:38
by bdeshi
Re: Elevated Command Prompt Option?
Posted: 22 Aug 2014 13:39
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)...
Re: Elevated Command Prompt Option?
Posted: 22 Aug 2014 14:14
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
Re: Elevated Command Prompt Option?
Posted: 22 Aug 2014 14:30
by highend
You've right clicked my button (to get an elevated 64bit CMD)?
Re: Elevated Command Prompt Option?
Posted: 22 Aug 2014 14:39
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.

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
Re: Elevated Command Prompt Option?
Posted: 22 Aug 2014 14:45
by Jeff Bellune
I successfully modified the script. That's about as much scripting skill as I have.
Thanks again,
Jeff
Re: Elevated Command Prompt Option?
Posted: 22 Aug 2014 15:38
by Jeff Bellune
Just thought I'd share the end result. Everything works as expected:
CmdButtonInfoTip.jpg
RightClickCmdButton.jpg
Cheers,
Jeff
Re: Elevated Command Prompt Option?
Posted: 22 Aug 2014 15:50
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?
Re: Elevated Command Prompt Option?
Posted: 22 Aug 2014 15:54
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