How to run PowerShell with admin privileges from current folder?

10,602

Solution 1

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

Solution 2

As LotPings mentions in the comments, you can add a simple shortcut to the Quck Access Toolbar if you are running Windows 10. It's supported by Windows by default.

This image should explain how to set it up. Shortcut powershell-admin

While this doesn't use shift, you still have a quick way of starting PowerShell in the current directory as admin.

Solution 3

Dominik's registry solution works well, but there is a problem when the folder path contains spaces. In the command, you have to add (escaped, i.e. double) apostrophes around the path.

C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -windowstyle hidden -Command "Start-Process powershell -ArgumentList '-NoExit', '-Command cd ''%V''' -Verb runAs"

Share:
10,602
Dominik
Author by

Dominik

Jestem osobą energiczną, nie lubiącą stać w miejscu. Lubię angażować się w ciekawe projekty i podejmować wyzwania, ponieważ daje mi to energię i motywację do dalszego działania. W moim życiu podejmowałem się wielu zadań. W najmłodszych latach śpiewałem, należałem do zespołu muzycznego, grałem na gitarze. Informatyką interesowałem się już w szkole podstawowej, na początku naprawiałem sprzęt komputerowy w domu, a także w mojej miejscowości. Będąc w gimnazjum angażowałem się w szkole jako kamerzysta i nagrywałem i montowałem wszystkie szkolne uroczystości. W liceum kontynuowałem to, a dodatkowo zająłem się programowaniem oraz zdobywaniem kwalifikacji w tym kierunku. Rozpocząłem to poprzez podjęcie się kursu Cisco „IT Essentials: PC Hardware and Software”, po którym otrzymałem certyfikat jego ukończenia. Realizowałem swoje pasje również w programowaniu układów firmy Atmel. Na studiach uczęszczam na różnego typu kursy i szkolenia. Na pierwszym roku nawiązałem kontakty handlowe z państwami dalekiego wschodu, głównie przez serwis aliexpress. Na drugim postanowiłem podjąć praktykę, nawiązałem więc kontakt z Narodowym Centrum Promieniowania Synchrotronowego SOLARIS. Jednocześnie kandydowałem na Prezesa Koła Naukowego IT, po czym zorganizowałem wybranym pracownikom z SOLARIS'u prelekcje na mojej uczelni. Owocem tych prelekcji było zdobycie pracy przez dwóch studentów w wyżej wymienionej firmie.

Updated on July 27, 2022

Comments

  • Dominik
    Dominik over 1 year

    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?

  • Admin
    Admin over 7 years
    Thanks Jonas, had at the time no access to an english Win10.