Launch Windows Terminal as Admin from Windows 11 Context Menu

In the article “11 Must-Have Apps for Windows 11” I talked about how much I love Windows 11 despite its few shortcomings. One of those is particularly annoying for IT folks like you and me. There’s no way of launching PowerShell or rather Windows Terminal as Administrator directly from File Explorer.

While looking for a plausible solution, I stumbled upon a Windows App called Custom Context Menu. Despite the app being listed for $1, there’s an unlimited free trial. But please consider buying the app if you want to support the Dev.

This app allows you to create your own modern context menu entries for specific file types or folders. These are the settings which you need to add in order to add “Open in Windows Terminal (Admin)” to your Windows 11 Context Menu.

alt text

Choose C:\Windows\System32\cmd.exe as your executable and use the following code as your Param. As with any syntax, the exact order and number of double quotes is extremely important here. It took me quite a few tries to get it right.

1
"cmd /c "cd "{path}" & powershell Start-Process wt -verb runas""

Enter a path for whatever icon you want under Icon and only toggle the Match Folder switch.

Alternatively, you can also click on the folder icon located in the top left corner and just create a new JSON file with the following content.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
{
  "title": "Open in Windows Terminal (Admin)",
  "exe": "\"C:\\Windows\\System32\\cmd.exe\"",
  "param": "\"cmd /c \"cd \"{path}\" & powershell Start-Process wt -verb runas\"\"",
  "icon": "\"C:\\Temp\\wtAdmin\\Terminal2.ico\"",
  "acceptExts": "",
  "acceptDirectory": true,
  "acceptFile": false,
  "acceptMultipleFilesFlag": 0,
  "pathDelimiter": "",
  "paramForMultipleFiles": "",
  "index": 0
}

If you like, you can give your context menu entry a custom name by clicking the gear icon in the bottom right corner.

There’s only one menu entry for all your custom entries.

Click save and either restart explorer.exe or your PC. This is very important as the menu won’t load without a restart.

How It Looks and Behaves

When you right click in any folder, you should see your custom context menu and choose “Open in Windows Terminal (Admin)” or whatever name you entered.

This will launch CMD, which will prompt for UAC and finally open WT (PS) as admin in the current folder.

Once PowerShell is opened, the CMD window will close automatically.

Make sure that you’ve set the Starting directory of the PowerShell Profile in Windows Terminal to “Use parent process directory”. Otherwise, Windows Terminal will not start in the current folder where you right clicked in Explorer.

Windows Terminal Settings

Adding More Entries

If you also want to add “Open in VS Code” to the modern context menu in Windows 11, you can add a second entry using the following code or configuration.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
{
  "title": "Open with VS Code",
  "exe": "\"C:\\Users\\marti\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\"",
  "param": "\"{path}\"",
  "icon": "\"C:\\Users\\marti\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\",0",
  "acceptExts": ".json .txt .ps1 .cmd .bat .py .yaml .md .html .js",
  "acceptDirectory": true,
  "acceptFile": true,
  "acceptMultipleFilesFlag": 0,
  "pathDelimiter": "",
  "paramForMultipleFiles": "",
  "index": 3
}

We can also use Match File here to bring up the custom menu for specific file types.

I hope that the option to launch Windows Terminal as admin or any other app really, also helps you be more productive. Initially, I discovered this app because I was looking for an easy way to bulk convert HEIC or HEIF images to JPG. Once I realized the potential of this App, I just had to figure out the correct params to launch WT as admin. I will definitely write another blog post about how to convert HEIC images to JPG using the same app and ImageMagick CLI.

Sneak-Peak of HEIC to JPG conversion in Windows 11 Custom Context Menu

Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Hosted on GitHub Pages
Built with Hugo
Theme Stack designed by Jimmy