[TC9.51] incomplete WM_SETTINGCHANGE handle: TC ignores an environment variable remove

Please report only one bug per message!

Moderators: white, Hacker, petermad, Stefan2

Post Reply
andry81
Junior Member
Junior Member
Posts: 97
Joined: 2018-11-22, 19:17 UTC

[TC9.51] incomplete WM_SETTINGCHANGE handle: TC ignores an environment variable remove

Post by *andry81 »

* Windows x64 Pro SP1

If try to directly remove an environment variable from the registry: `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment`

and then send globally `WM_SETTINGCHANGE` window message, then the TC ignores removed variable.

I use this vbs script to trigger `WM_SETTINGCHANGE`:
Set objShell = WScript.CreateObject("WScript.Shell")
Set objSystemEnv = objShell.Environment("System")
' triggers WM_SETTINGCHANGE
objSystemEnv("Path") = objSystemEnv("Path")
The script must be called under the Administrator privileges.

For example, the Windows Explorer correctly handles that case.
User avatar
elgonzo
Power Member
Power Member
Posts: 866
Joined: 2013-09-04, 14:07 UTC

Re: [TC9.51] incomplete WM_SETTINGCHANGE handle: TC ignores an environment variable remove

Post by *elgonzo »

I can confirm with both TC 9.51 32-bit and 64-bit on Win7 Pro x64.

It seems TC only looks for new or changed environment variables when receiving WM_SETTINGCHANGE but does not check for expired environment variables it still holds a copy of.


By the way, manually editing the registry is not required to reproduce the problem.
For convenience, here step-by-step instructions to reproduce the problem using just vbs scripts. (Don't close TC between the steps, keep it running.)


1. Make sure there is no TEST environment variable defined.

2. In TC's command line, enter the following to print the non-existing TEST variable:

Code: Select all

cmd /c echo %Test% && pause
Note how it just outputs "%Test%" (which is cmd.exe's "normal" way of echoing an unset environment variable)

3. Run this VBS script with admin privileges:

Code: Select all

Set objShell = WScript.CreateObject("WScript.Shell")
Set objSystemEnv = objShell.Environment("System")
objSystemEnv("Test") = "Kaboom"
4. In TC's command line, again enter the following to print the now existing TEST variable:

Code: Select all

cmd /c echo %Test% && pause
This time, as expected, it outputs "Kaboom".

5. Now run this VBS script with admin privileges:

Code: Select all

Set objShell = WScript.CreateObject("WScript.Shell")
Set objSystemEnv = objShell.Environment("System")
objSystemEnv.Remove("Test")
6. In TC's command line, enter once more the following to print the TEST variable (which shouldn't be set anymore):

Code: Select all

cmd /c echo %Test% && pause
The output is still "Kaboom", and not "%Test%" as expected.
Begrudgingly back to Windows... now 11... sigh... but i have no nerve for Linux desktop anymore...
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48012
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [TC9.51] incomplete WM_SETTINGCHANGE handle: TC ignores an environment variable remove

Post by *ghisler(Author) »

It seems TC only looks for new or changed environment variables when receiving WM_SETTINGCHANGE but does not check for expired environment variables it still holds a copy of.
Yes, that's exactly what it does! Why? You can add environment variables to a program AFTER launching the program. This is what TC does with variables like %commander_path% etc. I do not want to remove such variables when I get a WM_SETTINGCHANGE, but I cannot know which were added later and which not.
Author of Total Commander
https://www.ghisler.com
Post Reply