问题描述
我有一个适用于我的应用程序的 MSI 安装程序,它会向路径环境变量中写入一些内容,但在我重新启动或手动进入环境变量并单击确定"之前不会在 Windows 中刷新".
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.
安装程序有限,但我可以选择在安装完成后运行批处理文件或 VBScript.
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?
推荐答案
如果重启不是一个选项,你可以尝试杀死 explorer.exe 的每个实例,但我认为这也是不可接受的.
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.
正确的做法是向所有最顶层的窗口发送消息以通知环境中的变化.但我不知道操作系统中有什么可以做到这一点.如果您可以包含一个 exe 并可以访问 c 编译器,这应该可以解决问题
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
);
}
我已经尝试在 Windows 7 64 中使用 mingw/gcc 编译它,似乎没有问题.
I've tried compiling it with mingw/gcc in Windows 7 64 and seems to work without problems.
这篇关于Windows 7 安装程序,刷新路径环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!