Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Open Powershell as Admin on Right-Click (Context Menu) #gistblog #windows #powershell

Open Powershell as Admin on Right-Click

I described how to set a context menu option to open a Powershell console on right click earlier.

To open Powershell as admin on right click, we can add a command to be executed on start to our registry entry like so

$stpath = pwd; Start-Process PowerShell -ArgumentList \"-NoExit\", \"-Command cd $stpath\" -verb RunAs

So our Command in the registry entry will look like the following

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -windowstyle hidden -Command $stpath = pwd; Start-Process PowerShell -ArgumentList \"-NoExit\", \"-Command cd $stpath\" -verb RunAs

The downside of this approach is that first a normal Powershell window is opened, which opens a new Powershell window as admin if the user has the priviledges, and then the original Powershell window closes in the background.

This results in a flicker when Powershell is run as admin. 😢

Run Powershell as Admin on right click

If you find a flickerless approach to doing this, please leave a comment on this gist. Thanks!


This comment has been minimized.

Copy link

figaw commented Sep 1, 2017

I came up with a possible solution here:

"make a copy of the program, and always run this as an administrator the original doesn’t have this option."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.