Administrative Command Prompt - PowerShell

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
VeeGee

Administrative Command Prompt - PowerShell

Post 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 ?

klownboy
Posts: 4414
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7462 at 100% 2560x1440

Re: Administrative Command Prompt - PowerShell

Post by klownboy »

Try: run "powershell -Command Start-Process PowerShell -Verb RunAs";

VeeGee

Re: Administrative Command Prompt - PowerShell

Post 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 !

klownboy
Posts: 4414
Joined: 28 Feb 2012 19:27
Location: Windows 11, 25H2 Build 26200.7462 at 100% 2560x1440

Re: Administrative Command Prompt - PowerShell

Post 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;

terrytw
Posts: 121
Joined: 03 Mar 2023 03:37

Re: Administrative Command Prompt - PowerShell

Post 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

Post Reply