Page 1 of 1

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

Posted: 2021-01-21, 22:12 UTC
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.

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

Posted: 2021-01-21, 22:59 UTC
by gdpr deleted 6
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.

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

Posted: 2021-01-22, 17:32 UTC
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.