Skip to content

Instantly share code, notes, and snippets.

@Ashwinning
Last active December 28, 2020 10:57
Show Gist options
  • Save Ashwinning/1cdf374b6f6680c595104bdf4e090548 to your computer and use it in GitHub Desktop.
Save Ashwinning/1cdf374b6f6680c595104bdf4e090548 to your computer and use it in GitHub Desktop.
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!

@figaw
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."

http://variable.dk/2017/09/01/right-click-powershell-as-admin/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment