Setting environment variables requires reboot on 64-bit

69,523

Solution 1

Check this question on ServerFault: How do you add a Windows environment variable without rebooting?

So to propagate the change to the list of environment variables, you can write a small program which broadcasts WM_SETTINGCHANGE message as described in KB article How to propagate environment variables to the system.

Solution 2

When you add or set an environment variable, a WM_SETTINGCHANGE message is sent to all programs to inform them of the change. However, any already running program will not get the updated environment, unless it can handle this message itself. Rebooting the system updates every program.

A workaround without rebooting:

  1. Kill and restart explorer.exe, allthough this does not work for every running process, and only for the current logged on user.
  2. Restart the process or program you want to use, ie. try this out with cmd.exe. Again, this only works for the logged on user.

So summing-up, in order to get this to work for every user, you still need to reboot.

Share:
69,523
Alan Spark
Author by

Alan Spark

I am a software developer on Code Rocket from Rapid Quality Systems, the pseudocode and flowchart design and visualization tool for Visual Studio, Eclipse and standalone. I enjoy C# programming, mobile and web development. I also play Keyboard and Saxophone and enjoy hill walking and cycling in my free time.

Updated on December 16, 2020

Comments

  • Alan Spark
    Alan Spark over 3 years

    I am working on an installer using Wix 3.5 that needs to set the system PATH environment variable.

    This is how I am setting the environment variable:

    <Directory Id="DirectoryName">
        <Component Id="ComponentID" Guid="{BE20AF67-5943-4AF4-BE66-226E2D4B844F}">
            <Environment Id="EnvironmentID" Name="PATH" Action="set" Value="the path" Part="last" Separator=";" System="yes" />
        </Component>
    </Directory>
    

    This seems to be working on 32-bit systems without requiring a reboot for the changes to be recognized. However, when I try it on 64-bit Windows 7 a reboot is required.

    Is this a known issue on 64-bit systems?

    Maybe the best approach would be to schedule a reboot to cover all bases.

    Thanks, Alan