Terminal not reading updated environment variables #12163

Closed
opened 2026-01-31 03:07:48 +00:00 by claunia · 9 comments
Owner

Originally created by @rashil2000 on GitHub (Jan 23, 2021).

Environment

Windows build number: 10.0.19042.0
Windows Terminal version (if applicable): 1.4.3243.0

Steps to reproduce

Go to Start menu and Edit/Add any environment variables.

Expected behavior

Any shells launched through WT should have the updated environment variables.

Actual behavior

Nothing happens. Even if I restart all WT windows. I have to restart my PC for changes to reflect. I have tried both the Store versions and the GitHub releases.

Opening PowerShell or CMD from anywhere else works as expected, they have the updated variables.

Originally created by @rashil2000 on GitHub (Jan 23, 2021). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment ```none Windows build number: 10.0.19042.0 Windows Terminal version (if applicable): 1.4.3243.0 ``` # Steps to reproduce Go to Start menu and Edit/Add any environment variables. # Expected behavior Any shells launched through WT should have the updated environment variables. # Actual behavior Nothing happens. Even if I restart all WT windows. I have to _restart my PC_ for changes to reflect. I have tried both the Store versions and the GitHub releases. Opening PowerShell or CMD from anywhere else works as expected, they have the updated variables.
claunia added the Needs-TriageResolution-ExternalNeeds-Tag-Fix labels 2026-01-31 03:07:48 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Jan 25, 2021):

Well this is just the dickens, I can't seem to get this to repro:

8862-env-vars-001

@DHowett any ideas here? I'm at a loss

@zadjii-msft commented on GitHub (Jan 25, 2021): Well this is just the dickens, I can't seem to get this to repro: ![8862-env-vars-001](https://user-images.githubusercontent.com/18356694/105719014-73e86b00-5ee7-11eb-8ffb-e8f8cde64898.gif) @DHowett any ideas here? I'm at a loss
Author
Owner

@rashil2000 commented on GitHub (Jan 25, 2021):

HI @zadjii-msft!

I would like to apologize for taking up your time.
I found the culprit - it was the SteelSeries Engine application.
I'll write the cause here in case (although very unlikely) encounters this.

You see, SteelSeries is a company that makes gaming peripherals. I have a keyboard with some extra hotkeys - that I can assign to launch any apps with a single key. The SteelSeries Engine is used to manage/run the keyboard. I have assigned various keys to run different Windows Terminal profiles (CMD, PowerShell, WSL etc.). Since the processes launched by this Engine are children of the Engine itself, the processes won't have updated environment variables until and unless the Engine itself is restarted (so that the Engine itself runs with up to date variables in environment).

I'll close this now.

@rashil2000 commented on GitHub (Jan 25, 2021): HI @zadjii-msft! I would like to apologize for taking up your time. I found the culprit - it was the SteelSeries Engine application. I'll write the cause here in case (although very unlikely) encounters this. You see, [SteelSeries](https://steelseries.com/) is a company that makes gaming peripherals. I have a keyboard with some extra hotkeys - that I can assign to launch any apps with a single key. The SteelSeries Engine is used to manage/run the keyboard. I have assigned various keys to run different Windows Terminal profiles (CMD, PowerShell, WSL etc.). Since the processes launched by this Engine are children of the Engine itself, the processes won't have updated environment variables until and unless the Engine itself is restarted (so that the Engine itself runs with up to date variables in environment). I'll close this now.
Author
Owner

@zadjii-msft commented on GitHub (Jan 25, 2021):

Interesting! Thanks for following up, I haven't heard of that before so it'll be good to keep my eye out for something like this in the future.

@zadjii-msft commented on GitHub (Jan 25, 2021): Interesting! Thanks for following up, I haven't heard of that before so it'll be good to keep my eye out for something like this in the future.
Author
Owner

@LeoDupont commented on GitHub (Mar 11, 2021):

Thanks for the details @rashil2000, it helped me!
I have the same problem with Autohotkey: when opening WT with a hotkey from a forever-running AHK script, the environment variables are not reloaded.

@LeoDupont commented on GitHub (Mar 11, 2021): Thanks for the details @rashil2000, it helped me! I have the same problem with Autohotkey: when opening WT with a hotkey from a forever-running AHK script, the environment variables are not reloaded.
Author
Owner

@rashil2000 commented on GitHub (Mar 11, 2021):

Welcome @LeoDupont! Glad to see another member of AutoHotKey gang. I switched to shortly thereafter (I have Windows key + Enter set to launch wt.exe) as it removed dependence on external keyboard.

@rashil2000 commented on GitHub (Mar 11, 2021): Welcome @LeoDupont! Glad to see another member of AutoHotKey gang. I switched to shortly thereafter (I have Windows key + Enter set to launch wt.exe) as it removed dependence on external keyboard.
Author
Owner

@totkeks commented on GitHub (Jul 12, 2021):

Very interesting! This helped me too. I use the Microsoft Mouse and Keyboard center to configure the launch hotkeys (1, 2 and 3) and had the same issue, when running windows terminal through it.

@totkeks commented on GitHub (Jul 12, 2021): Very interesting! This helped me too. I use the Microsoft Mouse and Keyboard center to configure the launch hotkeys (1, 2 and 3) and had the same issue, when running windows terminal through it.
Author
Owner

@bestK commented on GitHub (Oct 28, 2022):


#`::
RefreshEnvironment()
Run C:\Users\WIN10\AppData\Local\Microsoft\WindowsApps\wt.exe

 RefreshEnvironment()
{
	Path := ""
	PathExt := ""
	RegKeys := "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment,HKCU\Environment"
	Loop, Parse, RegKeys, CSV
	{
		Loop, Reg, %A_LoopField%, V
		{
			RegRead, Value
			If (A_LoopRegType == "REG_EXPAND_SZ" && !ExpandEnvironmentStrings(Value))
				Continue
			If (A_LoopRegName = "PATH")
				Path .= Value . ";" 
			Else If (A_LoopRegName = "PATHEXT")
				PathExt .= Value . ";"
			Else 
				EnvSet, %A_LoopRegName%, %Value%
		}
	}
	EnvSet, PATH, %Path%
	EnvSet, PATHEXT, %PathExt%
}


ExpandEnvironmentStrings(ByRef vInputString)
{
	; get the required size for the expanded string
	vSizeNeeded := DllCall("ExpandEnvironmentStrings", "Str", vInputString, "Int", 0, "Int", 0)
	If (vSizeNeeded == "" || vSizeNeeded <= 0)
		return False ; unable to get the size for the expanded string for some reason
	
	vByteSize := vSizeNeeded + 1
	If (A_PtrSize == 8) { ; Only 64-Bit builds of AHK_L will return 8, all others will be 4 or blank
		vByteSize *= 2 ; need to expand to wide character sizes
	}
	VarSetCapacity(vTempValue, vByteSize, 0)
	
	; attempt to expand the environment string
	If (!DllCall("ExpandEnvironmentStrings", "Str", vInputString, "Str", vTempValue, "Int", vSizeNeeded))
		return False ; unable to expand the environment string
	vInputString := vTempValue
	
	; return success
	Return True
}

from https://www.autohotkey.com/board/topic/63858-function-to-refresh-environment-variables/

@bestK commented on GitHub (Oct 28, 2022): ``` #`:: RefreshEnvironment() Run C:\Users\WIN10\AppData\Local\Microsoft\WindowsApps\wt.exe RefreshEnvironment() { Path := "" PathExt := "" RegKeys := "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment,HKCU\Environment" Loop, Parse, RegKeys, CSV { Loop, Reg, %A_LoopField%, V { RegRead, Value If (A_LoopRegType == "REG_EXPAND_SZ" && !ExpandEnvironmentStrings(Value)) Continue If (A_LoopRegName = "PATH") Path .= Value . ";" Else If (A_LoopRegName = "PATHEXT") PathExt .= Value . ";" Else EnvSet, %A_LoopRegName%, %Value% } } EnvSet, PATH, %Path% EnvSet, PATHEXT, %PathExt% } ExpandEnvironmentStrings(ByRef vInputString) { ; get the required size for the expanded string vSizeNeeded := DllCall("ExpandEnvironmentStrings", "Str", vInputString, "Int", 0, "Int", 0) If (vSizeNeeded == "" || vSizeNeeded <= 0) return False ; unable to get the size for the expanded string for some reason vByteSize := vSizeNeeded + 1 If (A_PtrSize == 8) { ; Only 64-Bit builds of AHK_L will return 8, all others will be 4 or blank vByteSize *= 2 ; need to expand to wide character sizes } VarSetCapacity(vTempValue, vByteSize, 0) ; attempt to expand the environment string If (!DllCall("ExpandEnvironmentStrings", "Str", vInputString, "Str", vTempValue, "Int", vSizeNeeded)) return False ; unable to expand the environment string vInputString := vTempValue ; return success Return True } ``` from https://www.autohotkey.com/board/topic/63858-function-to-refresh-environment-variables/
Author
Owner

@i-zanis commented on GitHub (Jan 4, 2023):

Thanks for the details @rashil2000, it helped me! I have the same problem with Autohotkey: when opening WT with a hotkey from a forever-running AHK script, the environment variables are not reloaded.

Thanks for providing this answer.
How does this even happen?

@i-zanis commented on GitHub (Jan 4, 2023): > Thanks for the details @rashil2000, it helped me! I have the same problem with Autohotkey: when opening WT with a hotkey from a forever-running AHK script, the environment variables are not reloaded. Thanks for providing this answer. How does this even happen?
Author
Owner

@mobeigi commented on GitHub (Jul 21, 2024):

Wow glad I found this!

I use a AHK Script also to open WT in a directory from explorer (same as the Linux functionality) using the Control + Alt + T hotkey.

I always thought it was weird how WT.exe didn't immediately reflect env vars but now I know its because its the AHK spawning a child process that causes that behaviour. My workaround for now is to restart the AHK process whenever I change env vars although its not ideal.

In my opinion windows file explorer should just support the feature to let you spawn shells from the current directory using an easy hotkey. I know you can do it right now by clicking the address bar and typing wt.exe but that's not very efficient.

If anyone finds a way to do this naively without third party programs, let me know please!

@mobeigi commented on GitHub (Jul 21, 2024): Wow glad I found this! I use a [AHK Script](https://github.com/mobeigi/AutoHotKey-Scripts/blob/master/Windows%20Terminal%20Hotkey/windows-terminal-hotkey.ahk) also to open WT in a directory from explorer (same as the Linux functionality) using the Control + Alt + T hotkey. I always thought it was weird how WT.exe didn't immediately reflect env vars but now I know its because its the AHK spawning a child process that causes that behaviour. My workaround for now is to restart the AHK process whenever I change env vars although its not ideal. In my opinion windows file explorer should just support the feature to let you spawn shells from the current directory using an easy hotkey. I know you can do it right now by clicking the address bar and typing wt.exe but that's not very efficient. If anyone finds a way to do this naively without third party programs, let me know please!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#12163