Starting a ConPTY process with UAC elevation #496

Closed
opened 2026-01-30 21:53:43 +00:00 by claunia · 8 comments
Owner

Originally created by @Eugeny on GitHub (Dec 23, 2018).

What is the Microsoft's recommended way to start an elevated process with an attached PTY?

  1. CredUIPromptForWindowsCredentialsW + LogonUserW + CreateProcessWithTokenW?
  2. Running runas.exe with a PTY?
  3. Something else?
Originally created by @Eugeny on GitHub (Dec 23, 2018). What is the Microsoft's recommended way to start an elevated process with an attached PTY? 1) CredUIPromptForWindowsCredentialsW + LogonUserW + CreateProcessWithTokenW? 2) Running runas.exe with a PTY? 3) Something else?
claunia added the Issue-QuestionArea-InteropResolution-Won't-FixProduct-Conpty labels 2026-01-30 21:53:43 +00:00
Author
Owner

@Biswa96 commented on GitHub (Dec 23, 2018):

KernelBase.dll has an un-exported function CreatePseduoConsoleAsUser() which uses CreateProcessAsUserW(hToken, ...). The hToken parameter can be configured with admin privileges. It seems that the underlying conhost.exe process should also be run as administrator.

@Biswa96 commented on GitHub (Dec 23, 2018): `KernelBase.dll` has an un-exported function `CreatePseduoConsoleAsUser()` which uses `CreateProcessAsUserW(hToken, ...)`. The `hToken` parameter can be configured with admin privileges. It seems that the underlying `conhost.exe` process should also be run as administrator.
Author
Owner

@DHowett commented on GitHub (Dec 23, 2018):

@Biswa96 please do not encourage people to rely on our private APIs.

@DHowett commented on GitHub (Dec 23, 2018): @Biswa96 please do not encourage people to rely on our private APIs.
Author
Owner

@DHowett commented on GitHub (Dec 23, 2018):

@Eugeny we don’t have an official stance on elevating a pseudoconsole client. At the moment, you’d have the best chance of success by shipping an elevated helper and using that to broker communication with your lower-IL process.

@DHowett commented on GitHub (Dec 23, 2018): @Eugeny we don’t have an official stance on elevating a pseudoconsole client. At the moment, you’d have the best chance of success by shipping an elevated helper and using that to broker communication with your lower-IL process.
Author
Owner

@parkovski commented on GitHub (Jan 5, 2019):

I don't think the private API really matters here - when you call CreateProcessAsUser, you need to have SE_ASSIGNPRIMARYTOKEN_NAME, which restricted tokens don't have. So the only thing that API would help with is letting you create a PTY as another user if you are already elevated.

I'm experimenting with these scenarios here, but it's very experimental at the moment.

@parkovski commented on GitHub (Jan 5, 2019): I don't think the private API really matters here - when you call `CreateProcessAsUser`, you need to have `SE_ASSIGNPRIMARYTOKEN_NAME`, which restricted tokens don't have. So the only thing that API would help with is letting you create a PTY as another user _if you are already elevated_. I'm experimenting with these scenarios [here](https://github.com/parkovski/wsudo), but it's **very** experimental at the moment.
Author
Owner

@DHowett-MSFT commented on GitHub (May 18, 2019):

This discussion has, perhaps, outlived its usefulness.

@DHowett-MSFT commented on GitHub (May 18, 2019): This discussion has, perhaps, outlived its usefulness.
Author
Owner

@Biswa96 commented on GitHub (Sep 22, 2019):

The private API CreatePseduoConsoleAsUser() now becomes a open source one in src/winconpty/winconpty.cpp.

@Biswa96 commented on GitHub (Sep 22, 2019): The private API `CreatePseduoConsoleAsUser()` now becomes a open source one in `src/winconpty/winconpty.cpp`.
Author
Owner

@DHowett-MSFT commented on GitHub (Sep 22, 2019):

Creating a process as a different user was always possible, even without a pseudoconsole running as that user. The hard part is getting the correct part of the user's split token to launch elevated, which CreatePseudoConsoleAsUser still doesn't let you do. 😄

@DHowett-MSFT commented on GitHub (Sep 22, 2019): Creating a process as a different user was always possible, even without a pseudoconsole running as that user. The hard part is getting the correct part of the user's split token to launch _elevated_, which CreatePseudoConsoleAsUser _still_ doesn't let you do. :smile:
Author
Owner

@DHowett-MSFT commented on GitHub (Sep 22, 2019):

to wit: it is subject to the same limitation @parkovski already pointed out.

@DHowett-MSFT commented on GitHub (Sep 22, 2019): to wit: it is subject to the same limitation @parkovski already pointed out.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#496