[PR #8514] Enable auto-elevation for a profile #27219

Open
opened 2026-01-31 09:20:42 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/8514

State: closed
Merged: No


Summary of the Pull Request

This PR is a huge chunk of the implementation of my spec over in #8455. I know it's bad juju to send the implementation before the spec is approved, but here we are.

This PR adds two features:

  • the elevate: bool property to profiles
    • If the user is running unelevated, and elevate is set to true, then instead of opening a new tab, we'll open an elevated Terminal window with the profile.
    • Otherwise, we'll just open a new tab in the existing window. This includes cases where the window is elevated, and the profile is set to elevate:false. elevate:false basically just means "do nothing special with me".
  • the elevate: bool? property to NewTerminalArgs (newTab, splitPane)
    • This allows a user to create an action that will elevate the profile, even if the profile is not otherwise set to auto-elevate.
    • elevate:null (the default) does not change the profile's elevation status. The action will use whatever is set by the profile.
    • elevate:true will attempt to auto-elevate the profile
    • elevate:false will do nothing special.

References

PR Checklist

Detailed Description of the Pull Request / Additional comments

After playing with de-elevation a bit, it turns out it behaves weirdly with packaged applications. I can try and ask explorer.exe to launch the process on our behalf. However, if the thing we're launching is an execution alias (wt.exe), and we're elevated, then the child process will still launch elevated.

Validation Steps Performed

  • Ran tests
  • Opened a bunch of terminal tabs at various different elevation levels
  • opened new splits too

TODO

  • Add a dialog to ensure the user knows what thing they're about to elevate. Either that, or we need to manually put the commandline of the profile in the UAC dialog (not too hard - we'd just take the commandline from the final TerminalSettings and use that)
    • This is pending a bigger review in the spec.
  • Opening an elevated profile from the jumplist will create an empty (unelevated) terminal window that can't be closed. We'll need to update the jumplist logic to handle elevated profiles
  • What happens if the defaultProfile is set to elevate:true? Probably the same thing as the above. Might need a provision to have the first launch check if the profile we're about to create is elevated, and just bail after launching it.
  • If the Terminal exits before the elevated child spawns, then the elevation won't complete. I tried just having the original terminal bail to fix the above TODOs, but that revealed this one. I might need to use ShellExecuteEx so I can indicate the caller might go away before the child is launched.
**Original Pull Request:** https://github.com/microsoft/terminal/pull/8514 **State:** closed **Merged:** No --- ## Summary of the Pull Request This PR is a huge chunk of the implementation of my spec over in #8455. I know it's bad juju to send the implementation before the spec is approved, but here we are. This PR adds two features: * the `elevate: bool` property to profiles - If the user is running unelevated, **and** `elevate` is set to `true`, then instead of opening a new tab, we'll open an elevated Terminal window with the profile. - Otherwise, we'll just open a new tab in the existing window. This includes cases where the window is elevated, and the profile is set to `elevate:false`. `elevate:false` basically just means "do nothing special with me". * the `elevate: bool?` property to `NewTerminalArgs` (`newTab`, `splitPane`) - This allows a user to create an action that will elevate the profile, even if the profile is not otherwise set to auto-elevate. - `elevate:null` (_the default_) does not change the profile's elevation status. The action will use whatever is set by the profile. - `elevate:true` will attempt to auto-elevate the profile - `elevate:false` will do nothing special. ## References * #5000 for obvious reasons * Spec'd in #8455 ## PR Checklist * [x] Closes #632 * [x] I work here * [x] Tests added/passed * [n/a] Requires documentation to be updated ## Detailed Description of the Pull Request / Additional comments After playing with de-elevation a bit, it turns out it behaves weirdly with packaged applications. I can try and ask `explorer.exe` to launch the process on our behalf. However, if the thing we're launching is an execution alias (`wt.exe`), and we're elevated, then the child process will _still launch elevated_. ## Validation Steps Performed * Ran tests * Opened a bunch of terminal tabs at various different elevation levels * opened new splits too ## TODO * [ ] Add a dialog to ensure the user knows what thing they're about to elevate. Either that, or we need to manually put the commandline of the profile in the UAC dialog (not too hard - we'd just take the commandline from the final `TerminalSettings` and use that) - _This is pending a bigger review in the spec._ * [x] Opening an elevated profile from the jumplist will create an empty (unelevated) terminal window that _can't be closed_. We'll need to update the jumplist logic to handle elevated profiles * [x] What happens if the `defaultProfile` is set to `elevate:true`? Probably the same thing as the above. Might need a provision to have the first launch check if the profile we're about to create is elevated, and just bail after launching it. * [x] **If the Terminal exits before the elevated child spawns, then the elevation won't complete**. I tried just having the original terminal bail to fix the above TODOs, but that revealed this one. I might need to use `ShellExecuteEx` so I can indicate the caller might go away before the child is launched.
claunia added the pull-request label 2026-01-31 09:20:42 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#27219