[PR #12137] [MERGED] Profile auto-elevation, version 3 #28856

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/12137
Author: @zadjii-msft
Created: 1/11/2022
Status: Merged
Merged: 1/12/2022
Merged by: @undefined

Base: mainHead: dev/migrie/f/632-attempt-4


📝 Commits (4)

📊 Changes

18 files changed (+689 additions, -19 deletions)

View changed files

📝 OpenConsole.sln (+46 -3)
📝 doc/cascadia/profiles.schema.json (+11 -1)
📝 src/cascadia/CascadiaPackage/CascadiaPackage.wapproj (+3 -0)
src/cascadia/ElevateShim/elevate-shim.cpp (+53 -0)
src/cascadia/ElevateShim/elevate-shim.rc (+69 -0)
src/cascadia/ElevateShim/elevate-shim.vcxproj (+34 -0)
src/cascadia/ElevateShim/resource.h (+16 -0)
📝 src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp (+262 -0)
📝 src/cascadia/TerminalApp/TabManagement.cpp (+16 -2)
📝 src/cascadia/TerminalApp/TerminalPage.cpp (+139 -9)
📝 src/cascadia/TerminalApp/TerminalPage.h (+5 -0)
📝 src/cascadia/TerminalSettingsModel/ActionArgs.h (+8 -1)
📝 src/cascadia/TerminalSettingsModel/ActionArgs.idl (+9 -2)
📝 src/cascadia/TerminalSettingsModel/MTSMSettings.h (+2 -1)
📝 src/cascadia/TerminalSettingsModel/Profile.idl (+2 -0)
📝 src/cascadia/TerminalSettingsModel/TerminalSettings.cpp (+10 -0)
📝 src/cascadia/TerminalSettingsModel/TerminalSettings.h (+2 -0)
📝 src/cascadia/TerminalSettingsModel/TerminalSettings.idl (+2 -0)

📄 Description

Summary of the Pull Request

This is the resurrection of #8514 and #11310. WE determined that we didn't want to do #11308 after all, so this should be profile auto-elevation, without the warning.

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.

There's also something super BODGEY at work here. ShellExecute is the function we use to ask the OS to elevate something for us. But ShellExecute needs to be able to send a window message to the process that called it (if the caller was a WINDOWS subsystem application). So if we die immediately after calling ShellExecute, then the elevated process never actually spawns - sad. So we're adding a helper process, elevate-shim.exe, that lives in our process. That'll be the one that actually calls ShellExecute, so that it can live for the duration of the UAC prompt.

Validation Steps Performed

  • Ran tests
  • Opened a bunch of terminal tabs at various different elevation levels
  • opened new splits too
  • In the defaults (base layer) as well, for madness

Some settings to use for testing

    "keybindings" :
    [
        ////////// ELEVATION ///////////////
        { "keys": "f1", "name": "ELEVATED TAB", "icon": "\uEA18", "command": { "action": "newTab", "elevate": true } },
        { "keys": "f2", "name": "ELEVATED, Color", "icon": "\uEA18", "command": {
            "action": "newTab", "elevate": true, "commandline": "PowerShell.exe", "startingDirectory": "C:\\Windows", "tabColor": "#bbaa00"
        } },
        { "keys": "f3", "name": "unelevated ELEVATED", "icon": "🙃", "command": {
            "action": "newTab", "elevate": false, "profile": "elevated cmd"
        } },
        //////////////////////////////
    ],

    "profiles":
    {
        "defaults":
        {
            "elevate": true,
        },
        "list":
        [
            {
                "hidden":false,
                "name" : "cmd",
                "commandline" : "cmd.exe",
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "startingDirectory" : "%USERPROFILE%",
                "opacity" : 20
            },
            {
                "name" : "the COOLER cmd",
                "commandline" : "c:\\windows\\system32\\cmd.exe",
                "startingDirectory" : "%USERPROFILE%",
            },
            {
                "name" : "the sneaky cmd",
                "commandline" : "c:\\windows\\system32\\cmd.exe /k echo sneaky sneaks",
                "startingDirectory" : "%USERPROFILE%",
            },
            {
                "name": "elevated cmd",
                "commandline": "cmd.exe /k echo This profile is always elevated",
                "startingDirectory" : "well this is garbage",

                "elevate": true,
                "background": "#9C1C0C",
                "tabColor": "#9C1C0C",
                "colorScheme": "Desert"
            },
            {
                "name": "unelevated cmd",
                "commandline": "cmd.exe /k echo This profile is just as elevated as you started with",
                "elevate": false,
                "background": "#1C0C9C",
                "tabColor": "#1C0C9C",
                "colorScheme": "DotGov",
                "useAcrylic": true
            },
        ]

Also try:

  • wtd nt -p "elevated cmd" ; sp -p "elevated cmd"
  • wtd nt -p "elevated cmd" ; nt -p "elevated cmd"

This was merged manually via

git diff dev/migrie/f/non-terminal-content-elevation-warning dev/migrie/f/632-on-warning-dialog > ..\632.patch
git apply ..\632.patch --ignore-whitespace --reject

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/12137 **Author:** [@zadjii-msft](https://github.com/zadjii-msft) **Created:** 1/11/2022 **Status:** ✅ Merged **Merged:** 1/12/2022 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `dev/migrie/f/632-attempt-4` --- ### 📝 Commits (4) - [`5caa902`](https://github.com/microsoft/terminal/commit/5caa90240c73d5f4faca38f3e353c5cb1713af54) Profile auto-elevation, version 3 - [`17f6f97`](https://github.com/microsoft/terminal/commit/17f6f97325672517175d31ef05f4fff5672bdc72) i didnt update the schema - [`49ba461`](https://github.com/microsoft/terminal/commit/49ba461bd55d3f47442d3b2fc295aa4cfe851b3c) I think this fixed audit mode - [`91c27e7`](https://github.com/microsoft/terminal/commit/91c27e73dd77d41068e80dbe5298b7bc47e8775e) yea okay ### 📊 Changes **18 files changed** (+689 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `OpenConsole.sln` (+46 -3) 📝 `doc/cascadia/profiles.schema.json` (+11 -1) 📝 `src/cascadia/CascadiaPackage/CascadiaPackage.wapproj` (+3 -0) ➕ `src/cascadia/ElevateShim/elevate-shim.cpp` (+53 -0) ➕ `src/cascadia/ElevateShim/elevate-shim.rc` (+69 -0) ➕ `src/cascadia/ElevateShim/elevate-shim.vcxproj` (+34 -0) ➕ `src/cascadia/ElevateShim/resource.h` (+16 -0) 📝 `src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp` (+262 -0) 📝 `src/cascadia/TerminalApp/TabManagement.cpp` (+16 -2) 📝 `src/cascadia/TerminalApp/TerminalPage.cpp` (+139 -9) 📝 `src/cascadia/TerminalApp/TerminalPage.h` (+5 -0) 📝 `src/cascadia/TerminalSettingsModel/ActionArgs.h` (+8 -1) 📝 `src/cascadia/TerminalSettingsModel/ActionArgs.idl` (+9 -2) 📝 `src/cascadia/TerminalSettingsModel/MTSMSettings.h` (+2 -1) 📝 `src/cascadia/TerminalSettingsModel/Profile.idl` (+2 -0) 📝 `src/cascadia/TerminalSettingsModel/TerminalSettings.cpp` (+10 -0) 📝 `src/cascadia/TerminalSettingsModel/TerminalSettings.h` (+2 -0) 📝 `src/cascadia/TerminalSettingsModel/TerminalSettings.idl` (+2 -0) </details> ### 📄 Description ## Summary of the Pull Request This is the resurrection of #8514 and #11310. WE determined that we didn't want to do #11308 after all, so this should be profile auto-elevation, without the warning. 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 * [ ] Requires documentation to be updated - sure does, but that'll come all at the end. ## 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_. There's also something super BODGEY at work here. `ShellExecute` is the function we use to ask the OS to elevate something for us. But `ShellExecute` needs to be able to send a window message to the process that called it (if the caller was a WINDOWS subsystem application). So if we die immediately after calling `ShellExecute`, then the elevated process never actually spawns - sad. So we're adding a helper process, `elevate-shim.exe`, that lives in our process. That'll be the one that actually calls `ShellExecute`, so that it can live for the duration of the UAC prompt. ## Validation Steps Performed * Ran tests * Opened a bunch of terminal tabs at various different elevation levels * opened new splits too * In the defaults (base layer) as well, for madness Some settings to use for testing <details> ```jsonc "keybindings" : [ ////////// ELEVATION /////////////// { "keys": "f1", "name": "ELEVATED TAB", "icon": "\uEA18", "command": { "action": "newTab", "elevate": true } }, { "keys": "f2", "name": "ELEVATED, Color", "icon": "\uEA18", "command": { "action": "newTab", "elevate": true, "commandline": "PowerShell.exe", "startingDirectory": "C:\\Windows", "tabColor": "#bbaa00" } }, { "keys": "f3", "name": "unelevated ELEVATED", "icon": "🙃", "command": { "action": "newTab", "elevate": false, "profile": "elevated cmd" } }, ////////////////////////////// ], "profiles": { "defaults": { "elevate": true, }, "list": [ { "hidden":false, "name" : "cmd", "commandline" : "cmd.exe", "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}", "startingDirectory" : "%USERPROFILE%", "opacity" : 20 }, { "name" : "the COOLER cmd", "commandline" : "c:\\windows\\system32\\cmd.exe", "startingDirectory" : "%USERPROFILE%", }, { "name" : "the sneaky cmd", "commandline" : "c:\\windows\\system32\\cmd.exe /k echo sneaky sneaks", "startingDirectory" : "%USERPROFILE%", }, { "name": "elevated cmd", "commandline": "cmd.exe /k echo This profile is always elevated", "startingDirectory" : "well this is garbage", "elevate": true, "background": "#9C1C0C", "tabColor": "#9C1C0C", "colorScheme": "Desert" }, { "name": "unelevated cmd", "commandline": "cmd.exe /k echo This profile is just as elevated as you started with", "elevate": false, "background": "#1C0C9C", "tabColor": "#1C0C9C", "colorScheme": "DotGov", "useAcrylic": true }, ] ``` </details> Also try: * `wtd nt -p "elevated cmd" ; sp -p "elevated cmd"` * `wtd nt -p "elevated cmd" ; nt -p "elevated cmd"` This was merged manually via ``` git diff dev/migrie/f/non-terminal-content-elevation-warning dev/migrie/f/632-on-warning-dialog > ..\632.patch git apply ..\632.patch --ignore-whitespace --reject ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:31:14 +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#28856