I’m writing a program using C++ that takes advantage of a custom system-wide environment variable. That variable is set by an msi installer. Later my program reads it using GetEnvironmentVariable() API.
The problem is that it seems like the system needs to be rebooted for my custom environment variable to be visible in my program and I’d hate to reboot the system just for that.
What seems to be odd is that if (without rebooting) I right-click on My Computer and then go into Properties -> Advanced and click on “Environment variables” my custom environment variable is in that list but for some reason GetEnvironmentVariable() still doesn’t see it.
So is there any other API that I can use that will work without rebooting the system? (As system properties can clearly see it then.)
If you want to do this without rebooting the system you need to broadcast it. Something along the lines of
Explorer handles this message correctly so programs started after this broadcast will see the changes.
login will suffice