As far as I know, there's no OS provided way to monitor changes to environment variables. Most apps read these variables at startup and don't bother with changes till the next time they are run. There is something you could try as a workaround though. In recent versions of Windows, environment variables are persisted in the registry. So instead of monitoring for changes directly, you could examine/monitor the following two registry keys:
- HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
- HKEY_CURRENT_USER\Environment
And as to how you can monitor the registry, WMI provides a
RegistryValueChangeEvent
class that you can use to monitor changes to a specific key or value. But if I were you, I'd rethink my design and make it a basic expectation that the app will not be affected by environment variable changes once it's been started.