SessionName environment variable undefined #19243

Closed
opened 2026-01-31 06:37:52 +00:00 by claunia · 6 comments
Owner

Originally created by @Tabiskabis on GitHub (Jan 20, 2023).

Windows Terminal version

1.15.3465.0

Windows build number

10.0.1945.2486

Other Software

No response

Steps to reproduce

Start Terminal. Make sure to start Terminal directly - not cmd.exe or powershell.exe which get redirected to Terminal (different behaviour).
Output the environment variable named SessionName.
cmd.exe: if not defined SessionName (echo undefined) else echo %SessionName%

Expected Behavior

Environment variable "SessionName" should be undeifined when terminal is started elevated/as admin.
IIRC, it might actually be defined if the invoking user is member of the Network Operators group.

When started normally as invoker/unelevated, SessionName should contain either an "RDP-Tcp#Session" string (only when using RDP) or "console" (physically using the PC).

In other words, conhost's behaviour is expected.

Actual Behavior

Environment variable "SessionName" is undefined, regardles of whether the terminal is started normally or elevated/as admin.

If anyone else is having the same problem, my current workaround is to modify settings.json :
add "commandline": "cmd.exe /D /C \">NUL 2>&1 fltmc.exe || set \"SessionName=buggy\" & cmd.exe\"",
next to "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",

Originally created by @Tabiskabis on GitHub (Jan 20, 2023). ### Windows Terminal version 1.15.3465.0 ### Windows build number 10.0.1945.2486 ### Other Software _No response_ ### Steps to reproduce Start Terminal. Make sure to start Terminal directly - not cmd.exe or powershell.exe which get redirected to Terminal (different behaviour). Output the environment variable named SessionName. cmd.exe: `if not defined SessionName (echo undefined) else echo %SessionName%` ### Expected Behavior Environment variable "SessionName" should be undeifined when terminal is started elevated/as admin. IIRC, it might actually be defined if the invoking user is member of the Network Operators group. When started normally as invoker/unelevated, SessionName should contain either an "RDP-Tcp#Session" string (only when using RDP) or "console" (physically using the PC). In other words, conhost's behaviour is expected. ### Actual Behavior Environment variable "SessionName" is undefined, regardles of whether the terminal is started normally or elevated/as admin. If anyone else is having the same problem, my current workaround is to modify `settings.json` : add `"commandline": "cmd.exe /D /C \">NUL 2>&1 fltmc.exe || set \"SessionName=buggy\" & cmd.exe\"",` next to `"guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",`
claunia added the Needs-TriageIssue-Bug labels 2026-01-31 06:37:52 +00:00
Author
Owner

@237dmitry commented on GitHub (Jan 20, 2023):

Environment variable "SessionName" is undefined

What is this variable?
Maybe WT_SESSION or WT_PROFILE_ID?

 $ dir env:WT*

Name                           Value
----                           -----
WT_PROFILE_ID                  {574e775e-4f2a-5b96-ac1e-a2962a402336}
WT_SESSION                     c3f793c5-98bd-40f8-a8cd-73fe0027b5c7
@237dmitry commented on GitHub (Jan 20, 2023): > Environment variable "SessionName" is undefined What is this variable? Maybe `WT_SESSION` or `WT_PROFILE_ID`? ```powershell $ dir env:WT* Name Value ---- ----- WT_PROFILE_ID {574e775e-4f2a-5b96-ac1e-a2962a402336} WT_SESSION c3f793c5-98bd-40f8-a8cd-73fe0027b5c7 ```
Author
Owner

@DHowett commented on GitHub (Jan 20, 2023):

What is this variable?

It's an environment variable provided by the Windows session manager that indicates how a user is connected to the machine (via remote desktop, sitting at the keyboard, etc.).

We'll look into this. Terminal is changing how it handles environment variables in #12516, after which it will regenerate them exactly the same way the Windows profile management service does. Perhaps that will fix this -- or at least make it clear why it doesn't work.

@DHowett commented on GitHub (Jan 20, 2023): > What is this variable? It's an environment variable provided by the Windows session manager that indicates how a user is connected to the machine (via remote desktop, sitting at the keyboard, etc.). We'll look into this. Terminal is changing how it handles environment variables in #12516, after which it will regenerate them exactly the same way the Windows profile management service does. Perhaps that will fix this -- or at least make it clear why it doesn't work.
Author
Owner

@237dmitry commented on GitHub (Jan 20, 2023):

It's an environment variable provided by the Windows session manager that indicates how a user is connected to the machine (via remote desktop, sitting at the keyboard, etc.).

I hear it for the first time. Never seen this variable. Should it be in the WT Preview?

@237dmitry commented on GitHub (Jan 20, 2023): > It's an environment variable provided by the Windows session manager that indicates how a user is connected to the machine (via remote desktop, sitting at the keyboard, etc.). I hear it for the first time. Never seen this variable. Should it be in the WT Preview?
Author
Owner

@Tabiskabis commented on GitHub (Jan 20, 2023):

I've looked into it a bit more. Apparently the variable is inherited from explorer.exe and is undefined in environments that are launched as services or scheduled task, or started manually via task manager. So it being unavailable in WT may be unexpected, but also I never should've relied on it.

@Tabiskabis commented on GitHub (Jan 20, 2023): I've looked into it a bit more. Apparently the variable is inherited from explorer.exe and is undefined in environments that are launched as services or scheduled task, or started manually via task manager. So it being unavailable in WT may be unexpected, but also I never should've relied on it.
Author
Owner

@carlos-zamora commented on GitHub (Jan 25, 2023):

Thanks for following up. In light of that, we're going to close this one out.

@carlos-zamora commented on GitHub (Jan 25, 2023): Thanks for following up. In light of that, we're going to close this one out.
Author
Owner

@carlos-zamora commented on GitHub (Jan 25, 2023):

@DHowett just confirmed that when we land #12516, session name will be present whenever Terminal is able to find the current session ID.

@carlos-zamora commented on GitHub (Jan 25, 2023): @DHowett just confirmed that when we land #12516, session name will be present whenever Terminal is able to find the current session ID.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19243