Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Peculiarity When Starting an Elevated TCC Session

Jun
1,092
48
When I issue the command start by itself, a new standalone TCC session starts in a ConPTY console, as expected.

However, when I issue the command start /elevated, an elevated standalone TCC session starts, but it is not in a ConPTY console. Is that WAD? If so, how can I start an elevated session in a ConPTY console?
 
What is a "ConPty console"? If you mean Windows Terminal (non-elevated) vs. classic console (elevated) then that is a (current, at least) Windows limitation. I have asked about it on GitHub/WindowsTerminal.

You should see the same behavior from the Run dialog (Win+R). When here:

1776171338487.webp


I get TCC in Windows Terminal if I press Enter and I get TCC in a console if I press Ctrl+Shift+Enter (and say OK at the UAC prompt).
 
I don't really understand all these things: Windows Terminal, classic console, pseudoconsole. I spend 99.9% of my time using TCC in Take Command tabs. Every so often, I want to run a standalone TCC session as administrator, so I was trying to launch every kind of session: normal and elevated, ConPTY and classic console.

You gave me a command that would tell me if I was in a pseudoconsole (ConPTY), and I built a command to display the answer and set a variable _ConPTY. When I run just start, I get TCC running in a window where that test returns "ConPTY = Yes" and _ConPTY=1. So my understanding was that TCC is running in a pseudoconsole. The window does have tabs.

When I run start /elevated, TCC opens in a window that looks different (no tabs). The test returns "ConPTY = No" and _Conpty=0. However, the extended ANSI control sequences (e.g., for underlining) work, as when TCC is running in a ConPTY console in a TCMD tab.

If I run

start /pgm C:\Windows\System32\conhost.exe %tcmdpgmdir\tcc.exe,​

I get a window that looks like the one I got with the elevated session. If I run

start /elevated /pgm C:\Windows\System32\conhost.exe %tcmdpgmdir\tcc.exe

I explicitly ran conhost.exe and get the same window as with the simple start /elevated. Does the latter use conhost, while the non-elevated command uses the pseudoconsole (ConPTY)?
 
Conhost.exe can provide the traditional Windows console window (ConsoleWindowClass), no tabs, think "DOS Box". That's what you're getting from START /ELEVATED. Conhost.exe can also provide a PseudoConsoleWindow class window; it's invisible and facilitates a ConPty. A ConPty is just an interface between a console app (like TCC) and a terminal emulator (like TCMD).

Older TCMDs used hidden ConsoleWindowClass class windows and mimicked what's going on there in TCMD tabs. TCMD 36 can still do that but it can alternatively use the ConPty approach ... TCC communicates with the ConPty and the ConPty communicates with the terminal emulator (TCMD).

WindowsTerminal is a relatively new terminal emulator from MS. It always uses the PseudoConsoleWindow/ConPty approach. Instead of using Conhost.exe to provide the ConPty (it probably could) it uses its own OpenConsole.exe. If you found OpenConsole.exe and did

Code:
[PathTo]\openconsole.exe [PathTo]\tcc.exe

it would be like your manually running conhost.exe.
 
TCC cannot run itself in a ConPTY session. Only a terminal host (like TCMD, WT, etc.) can do that, by creating the pseudoconsole and the pipes to communicate with it.

So, as Vince said, the only way to start an elevated ConPTY session is to use one of the pseudoconsole aware hosts.
 
As I consider this further, I think that what I was really trying to determine is whether or not my current TCC session supports the extended ANSI escape sequences, such as for underlined text. I can imagine a case in which a batch file might use alternate code for the two cases. Vince, can you give me a command that would tell me that?
 
I don't think "extended" is a yes/no question or if what you want even exists. In a typical case, shell and terminal both local, you should be able to figure whether the UI is a console, TCMD, WT, maybe others. But you'd have to be familiar with the capabilities of each. There are queries that can be sent, for example DA (device attributes), apparently honored by consoles, TCMD, and WT but you'd have to know (1) how to capture the response (which goes to STDIN) and (2) how to decode it. For example, here's DA in TCMD.

1776256583863.webp


I sent DA. The response, which went to STDIN, is now on my next command line! Is there a way to capture that response? I don't know. And I don't know what the numerical attributes mean.

Let me repeat that question. Is there a way to "capture" that response?

And those responses are mostly legacy, going back to the day of hardware terminals when, for example, there was no 24-bit color.
 
OK, thanks. I was hoping that there was something easy, like what you sent me to detect ConPTY.

Since this is really just an academic issue, I wouldn't ask that any more time be spent on it. As I said, I almost never run TCC outside of Take Command, and I know how to handle this there.
 
There is an internal TCC variable %_conpty which will return 1 if TCC is running in a pseudoconsole.

I'm pretty sure that I checked the help and did not see that variable. It is there now.

And if you're able to display underlined characters, you're definitely running in a pseudoconsole.

That isn't true and is part of how I got confused. I used to include the ansi underscore string in my prompt. Then, when the prompt was underlined, I knew that I was in ConPTY -- but for standalone TCC sessions not in ConPTY the underscore was still working.

Oh, I see that Vince has now responded as well.
 
That isn't true and is part of how I got confused. I used to include the ansi underscore string in my prompt. Then, when the prompt was underlined, I knew that I was in ConPTY -- but for standalone TCC sessions not in ConPTY the underscore was still working.

Stand-alone consoles can still be ConPTY sessions, if conhost or openconsole want them to be.
 
Stand-alone consoles can still be ConPTY sessions, if conhost or openconsole want them to be.

I'm not sure what you mean by that. If there is a way to start an elevated TCC session with ConPTY, please tell me how.
 
Back
Top