Context menu for windows bash admin

  • 9 months ago
Comment

ChatGPT
1 / 1

To add a context menu option for Windows Subsystem for Linux (WSL) in the context menu of files and folders, so that you can open a Bash shell as an administrator, follow these steps:

  1. Create a Registry File:
    Open a text editor and create a .reg file with the following content:

    plaintext
    Windows Registry Editor Version 5.00

    [HKEY_CLASSES_ROOT\Directory\shell\RunWSLAdmin]
    @="Open WSL as Administrator"
    "Icon"="%SystemRoot%\\System32\\bash.exe,0"

    [HKEY_CLASSES_ROOT\Directory\shell\RunWSLAdmin\command]
    @="cmd.exe /c start /b bash.exe -c 'sudo su -'"

    [HKEY_CLASSES_ROOT\Drive\shell\RunWSLAdmin]
    @="Open WSL as Administrator"
    "Icon"="%SystemRoot%\\System32\\bash.exe,0"

    [HKEY_CLASSES_ROOT\Drive\shell\RunWSLAdmin\command]
    @="cmd.exe /c start /b bash.exe -c 'sudo su -'"
  2. Save and Merge:
    Save the file with a .reg extension (e.g., WSLAdminContextMenu.reg). Then, double-click the .reg file to merge its content into the Windows Registry.

  3. Confirm Registry Changes:
    You might receive a security prompt. Confirm the changes by clicking "Yes" or "OK."

  4. Use the Context Menu:
    After merging the registry changes, you can right-click on a file or folder in Windows Explorer. You will see the "Open WSL as Administrator" option. Clicking on it will open a Bash shell with administrator privileges.

Note that modifying the Windows Registry can affect the system's behavior, so be cautious when making changes. Always back up your registry or create a system restore point before making any modifications.

Remember that this approach will open a Bash shell as an administrator, but you'll still need to provide your password for the sudo command within the Bash shell.

Keep in mind that these instructions are provided as-is, and you should proceed with caution. If you're not comfortable working with the Windows Registry, consider seeking assistance from someone who is more experienced with such tasks.