Profiles do not inherit environment variables **injected into explorer.exe with CreateRemoteThread** #10387

Closed
opened 2026-01-31 02:20:13 +00:00 by claunia · 10 comments
Owner

Originally created by @vefatica on GitHub (Aug 29, 2020).

Terminal's TEMP environment variable has the value z:. That's the same for Explorer.exe and shells running in consoles. And that's as desired.

For any (Windows) shell running in Terminal, TEMP=C:\Users\vefatica\AppData\Local\Temp.

How and why?

If this is a duplicate, please give a brief lesson in searching issues.

Originally created by @vefatica on GitHub (Aug 29, 2020). Terminal's TEMP environment variable has the value z:\. That's the same for Explorer.exe and shells running in consoles. And that's as desired. For any (Windows) shell running in Terminal, TEMP=C:\Users\vefatica\AppData\Local\Temp. How and why? If this is a duplicate, please give a brief lesson in searching issues.
claunia added the Resolution-By-DesignNeeds-Tag-Fix labels 2026-01-31 02:20:14 +00:00
Author
Owner

@DHowett commented on GitHub (Aug 30, 2020):

Please do not delete the bug template.

We made a change in #7243 to make sure clients of Terminal always received the newest possible environment variables available for your user. That practically means that it inherits directly from the same source as Explorer.

How are you setting TEMP such that it is not available to the user’s environment block?

@DHowett commented on GitHub (Aug 30, 2020): Please do not delete the bug template. We made a change in #7243 to make sure clients of Terminal always received the newest possible environment variables available for your user. That practically means that it inherits directly from the same source as Explorer. How are you setting `TEMP` such that it is not available to the user’s environment block?
Author
Owner

@vefatica commented on GitHub (Aug 30, 2020):

I'm not sure what you mean ... "bug template". I have been opening blank issues. Should I open a bug report (and leave the canned stuff there) even if I'm only curious?

My login script sets TEMP and TMP in explorer.exe and two other apps from which I launch almost everything. I do that with my own app which uses CreateRemoteThread after injecting some code and data. I could make the change in HKCU\Envoronment and broadcast WM_SETTINGSCHANGE but I'm not sure who's listening. Does explorer.exe honor that message by updating its environment?

@vefatica commented on GitHub (Aug 30, 2020): I'm not sure what you mean ... "bug template". I have been opening blank issues. Should I open a bug report (and leave the canned stuff there) even if I'm only curious? My login script sets TEMP and TMP in explorer.exe and two other apps from which I launch almost everything. I do that with my own app which uses CreateRemoteThread after injecting some code and data. I could make the change in HKCU\Envoronment and broadcast WM_SETTINGSCHANGE but I'm not sure who's listening. Does explorer.exe honor that message by updating its environment?
Author
Owner

@vefatica commented on GitHub (Aug 31, 2020):

Yes, explorer.exe responds to WM_SETTINGSCHANGE (lParam = "Environment") by updating its environment.

@vefatica commented on GitHub (Aug 31, 2020): Yes, explorer.exe responds to WM_SETTINGSCHANGE (lParam = "Environment") by updating its environment.
Author
Owner

@DHowett commented on GitHub (Sep 3, 2020):

Okay, the way you were setting environment variables is absolutely not a normal thing that anybody would ever do. It seems like you know your way around a Windows system, but have you ever wondered why you had to inject a thread into explorer just to set some environment variables? 😅

@DHowett commented on GitHub (Sep 3, 2020): Okay, the way you were setting environment variables is absolutely not a normal thing that anybody would ever do. It seems like you know your way around a Windows system, but have you ever wondered why you had to inject a thread into explorer just to set some environment variables? 😅
Author
Owner

@DHowett commented on GitHub (Sep 3, 2020):

(Gonna close this one by design. The reason I asked about the bug template -- which you don't have to use (!) -- is because sometimes the behaviors folks are asking about were changed and we like to know what version they're using. it helps us tailor the answer to the question more appropriately.)

@DHowett commented on GitHub (Sep 3, 2020): (Gonna close this one by design. The reason I asked about the bug template -- which you don't have to use (!) -- is because sometimes the behaviors folks are asking about were changed and we like to know what version they're using. it helps us tailor the answer to the question more appropriately.)
Author
Owner

@vefatica commented on GitHub (Sep 10, 2020):

Just curious ... does WT create that fresh environment with its bare hands (read all the registry environment keys) or are there API functions to do it ?

@vefatica commented on GitHub (Sep 10, 2020): Just curious ... does WT create that fresh environment with its bare hands (read all the registry environment keys) or are there API functions to do it ?
Author
Owner

@DHowett commented on GitHub (Sep 10, 2020):

It depends on whether you are asking so as to determine which API to patch at runtime.

@DHowett commented on GitHub (Sep 10, 2020): It depends on whether you are asking so as to determine which API to patch at runtime.
Author
Owner

@vefatica commented on GitHub (Sep 10, 2020):

I'm not going to do any patching (I don't know how). As I said, I'm just curious. I just discovered CreateEnvironmentBlock() and I'm about to try it.

@vefatica commented on GitHub (Sep 10, 2020): I'm not going to do any patching (I don't know how). As I said, I'm just curious. I just discovered CreateEnvironmentBlock() and I'm about to try it.
Author
Owner

@DHowett commented on GitHub (Sep 10, 2020):

In that case: Yep, that’s the one we use!

@DHowett commented on GitHub (Sep 10, 2020): In that case: Yep, that’s the one we use!
Author
Owner

@vefatica commented on GitHub (Sep 10, 2020):

Thanks!

@vefatica commented on GitHub (Sep 10, 2020): Thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#10387