Page 1 of 1
toolbar button for "open cmd as admin"
Posted: 17 Feb 2017 15:56
by jerrygoyal
There's a toolbar button for cmd but not for "cmd as admin". Is there any way to open cmd as admin?
Re: toolbar button for "open cmd as admin"
Posted: 17 Feb 2017 16:07
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...
Re: toolbar button for "open cmd as admin"
Posted: 17 Feb 2017 16:36
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.
Re: toolbar button for "open cmd as admin"
Posted: 17 Feb 2017 16:39
by highend
As long as it is the 64-bit cmd prompt on a 64-bit system, it's fine

Re: toolbar button for "open cmd as admin"
Posted: 17 Feb 2017 16:43
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.
Re: toolbar button for "open cmd as admin"
Posted: 17 Feb 2017 22:50
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!).

Re: toolbar button for "open cmd as admin"
Posted: 18 Feb 2017 16:48
by admin
I decided to handle this with a new scripting command: opencommandprompt.
Piece of cake to create a button for it then.
Re: toolbar button for "open cmd as admin"
Posted: 19 Feb 2017 00:31
by highend
Should start an elevated command prompt for the current directory.
But nothing happens. Literally nothing.
Same. It seems once the 4th the elevate flag is set the command refuses to do something...
Re: toolbar button for "open cmd as admin"
Posted: 19 Feb 2017 09:53
by admin
Oha!? Both works fine here. Win 8.1
Re: toolbar button for "open cmd as admin"
Posted: 19 Feb 2017 11:51
by highend
Win 7 x64 in an older notebook here. Don't have access to my other systems currently...
Re: toolbar button for "open cmd as admin"
Posted: 19 Feb 2017 12:39
by PeterH
To verify I've just tested both forms in W7pro X64: both work just as expected.
Re: toolbar button for "open cmd as admin"
Posted: 19 Feb 2017 14:10
by klownboy
Both prompts work in Windows 10 x64 .
Re: toolbar button for "open cmd as admin"
Posted: 19 Feb 2017 14:50
by JLoftus
Running version 17.50.0210, if I create a CTB with opencommandprompt; I am getting:
'opencommandprompt' is not a valid script command.
Re: toolbar button for "open cmd as admin"
Posted: 19 Feb 2017 15:01
by highend
You need 219^^
Re: toolbar button for "open cmd as admin"
Posted: 19 Feb 2017 15:24
by JLoftus
Got 222, now working great, thanks!