Run Bash As Admin From The Context Menu In Windows 10

The Anniversary Update added Bash to Windows 10. The feature in and of itself was the major highlight of the update. This feature is for developers and not the average end user. Bash in Windows 10 makes developing on the Windows platform much easier. It’s also a great way to get developers to upgrade to Windows 10 because you can’t get Bash natively on older versions of Windows. This is a Windows 10 only feature. Bash in Windows 10 is an optional feature so it isn’t integrated like the Command Prompt. If you want to run Bash as admin from the context menu, and be able to open it in any folder location you have to tweak the registry a bit. Here’s how.

Get Bash In Windows 10

Before you can run Bash as admin, you need to make sure you’ve installed it. The process is fairly simple; enable developer mode in the Settings app under For Developers. You will need admin rights to enable it.

After you turn it on, open the Control Panel app and go to Programs>Turn Windows Features On or Off. Select Windows Subsystem for Linux.

Open Command Prompt (with admin rights) and type Bash. Windows 10 will download and install Bash. It can take fifteen to thirty minutes to get it running.

Run Bash As Admin

It’s pretty easy to run Bash as admin but it just isn’t possible from the right-click context menu. You can launch the Bash app from the Windows Search menu or the Start menu but you can’t open it directly in a folder.

Open the Windows Registry. Type ‘regedit’ in the search bar and open it with administrative privileges. Navigate to the following location;

HKEY_CLASSES_ROOTDirectoryshell

Create a new subkey called AdminBash. The new key will have a default string value. Double-click it and change the value to the following.

Run Bash As Admin

Next, in the Bash Admin key you just created, create another key and name it Command. Inside this key, like the previous one, there is a string called Default. Double-click it and change the value to the following.

powershell -c start -verb runas cmd '/c start /D """%V""" bash.exe'

Restart Explorer.exe for good measure. Right-click a folder and select the Run Bash As Admin option from the context menu. Windows PowerShell will open and you will then be prompted to enter your admin password. Once you enter the password correctly, Bash will open.

A Caveat

Bash will not be able to open a folder that has spaces in its name. For example you can use the context menu option to open a folder called ‘Cool-Stuff’ but you cannot use it to open a folder called ‘Cool Stuff’. In Bash, this is usually circumvented by adding quotes around the folder name but the context menu option doesn’t allow that. This hack is therefore limited.

One of our readers Liandri has made this caveat obsolete. The value of the string has been updated in the previous section to the one suggested below in the comment. It was duly tested out and it worked flawlessly. This hack will now work for folder with or without spaces in their name. 

Bash on Windows 10 is available on the Anniversary Update and later builds.

قالب وردپرس

About Lily Herman

Lily Herman
Lily Herman is a New York-based writer and editor. In recent months, her work has been featured in Teen Vogue, Glamour, Refinery29, Cosmopolitan, TIME, Newsweek, Fast Company, and Mashable. You can check out her website, LinkedIn, and Twitter.

Leave a Reply

Your email address will not be published. Required fields are marked *