Warm tip: This article is reproduced from stackoverflow.com, please click
administrator powershell windows

How to run PowerShell with admin privileges from current folder?

发布于 2020-05-08 17:21:02

How can I run PowerShell from Context menu (holding the shift key) in current folder with admin privileges? Is there a simpler way than type in any code to windows registry?

Questioner
Dominik
Viewed
10
Dominik 2016-11-15 06:58

I have had the same problem recently. Answer unfortunately wasn't obvious and easy to find. There are some scripts on the internet but has worked form me. Below i am presenting to You script which You can paste into any file with reg extension and run. After that You will be able to run powershell with admin privileges from current open folder (You have to hold shift and then right click on empty space in folder.

Code:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\PowerShellAsAdmin]
@="Open PowerShell window here as administrator"
"Extended"=""
"HasLUAShield"=""
"Icon"="powershell.exe"

[HKEY_CLASSES_ROOT\Directory\Background\shell\PowerShellAsAdmin\command]
@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -windowstyle hidden -Command \"Start-Process powershell  -ArgumentList '-NoExit', '-Command cd %V' -Verb runAs\""

Context menu view:

enter image description here