Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
545 views
in Technique[技术] by (71.8m points)

vbscript - Windows 7 install program, refresh path environment variable

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 go into environment variables and click ok.

My client has requested that we fix this.

The install program is limited but I have the option to run a batch file or VBScript after installation is finished.

Anybody know if there is a command or a function I can use?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...