Windows 7 install program, refresh path environment variable

后端 未结 1 962
野趣味
野趣味 2020-12-12 00:44

I have an MSI install program for my application, that writes something to the path environment variable, but is is not \"refreshed\" in Windows until I reboot or manually g

相关标签:
1条回答
  • 2020-12-12 01:24

    If restart is not an option, you can try to kill every instance of explorer.exe, but i think this will also be not acceptable.

    The correct way of doing it is sending a message to all top most windows to notificate of changes in the environment. But i don't know anything in the OS to do that. If you can include an exe and have access to a c compiler, this should do the trick

    #include "windows.h"
    
    void main(void) {
        SendMessageTimeout(
            HWND_BROADCAST,
            WM_SETTINGCHANGE,
            (WPARAM) NULL,
            (LPARAM) "Environment",
            SMTO_NORMAL,
            1000,
            NULL
        );
    }
    

    I've tried compiling it with mingw/gcc in Windows 7 64 and seems to work without problems.

    0 讨论(0)
提交回复
热议问题