Page 1 of 1

Administrative Command Prompt - PowerShell

Posted: 14 Apr 2020 21:46
by VeeGee
Good afternoon all,
In my hamburger menu, to open an Administrative Command Prompt Here, I am using this :

Code: Select all

::Open Administrative Command Prompt Here;opencommandprompt , , , 1
and it works great !

I also have an entry to open a PowerShell Command Prompt Here :

Code: Select all

::Open PowerShell Command Prompt Here;run "powershell"
which also works great; however, I was looking for a way to make the PowerShell one open in elevated/Administrator mode, e.g. the same as 'right-click / Run as Administrator'.

I didn't see any option in the help on RUN for this. Any ideas or changes that I can try ?

Re: Administrative Command Prompt - PowerShell

Posted: 14 Apr 2020 22:12
by klownboy
Try: run "powershell -Command Start-Process PowerShell -Verb RunAs";

Re: Administrative Command Prompt - PowerShell

Posted: 15 Apr 2020 18:22
by VeeGee
Thank you. This works really well. The resulting window is in elevated mode; however, you lose the option of the prompt location being the location of the selected tab. I think I can work a ""cd <curfolder>"" into the -Command somehow. My initial attempt did open the prompt to the current folder location, but it loses the elevated state.

Probably just a matter of getting the order of the command prompt correct. I'll do some more tinkering this afternoon.
Thanks for the reply and helpful start !

Re: Administrative Command Prompt - PowerShell

Posted: 18 Apr 2020 18:58
by klownboy
Any luck yet? I installed the new(er) PowerShell 7 from here: https://github.com/PowerShell/PowerShel ... -preview.1.

Using that version, I was able to run a PowerShell Admin prompt in a specified folder by doing this: run "pwsh -Command Start-Process Pwsh -Verb RunAs -WorkingDirectory D:\tools",,0,0;

If you'd rather have PowerShell open in the current path do this: run "pwsh -Command Start-Process Pwsh -Verb RunAs -WorkingDirectory '<curpath>'",,0,0;

Re: Administrative Command Prompt - PowerShell

Posted: 08 Oct 2023 11:44
by terrytw
A quick note to anyone wishing to do the same:

pwsh is only available if you installed the standalone powershell core 6+.
If you use powershell with the command klownboy provided, it will fail because -WorkingDirectory only works with pwsh
If you wish to use the default powershell 5 that is bundled with windows 10 or 11, try this:

Code: Select all

run "PowerShell -Command Start-Process PowerShell -verb runAs -ArgumentList '-NoExit', '-Command', 'cd <curpath>'",,,0