- Revenera Community
- InstallShield Forum
- VB Script for WM_SETTINGCHANGE
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Printer Friendly Page
VB Script for WM_SETTINGCHANGE
In Windows 10 Environment variable does not get updated till you restart the computer.
Do you have working vb script to programmatically broadcast this message ?
Microsoft says that following code snippet should work. Directly copy pasting this code in vb script does not work.
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) "Environment", SMTO_ABORTIFHUNG, 5000, &dwReturnValue);
Thanks is advance.
prototype BOOL USER.SendMessageTimeout(HWND, SHORT, SHORT, POINTER, SHORT, SHORT, POINTER);
#define HWND_BROADCAST 0xFFFF
#define WM_SETTINGCHANGE 0x001A
#define SMTO_ABORTIFHUNG 0x0002
export prototype RefreshEnvironment(HWND);
POINTER pParam, pResult;
sParam = "Environment";
pParam = &sParam;
pResult = &lResult;
if (!SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, pParam, SMTO_ABORTIFHUNG, 100, pResult))
SprintfBox(WARNING, "", "SendMessageTimeout failed in RefreshEnvironment, Error %d", GetLastError());
If you author the Environment table to install environment variables, a WM_SETTINGCHANGE message should be sent by the WriteEnvironmentStrings action. I had a quick test with a Basic MSI project just installing a new environment variable using the Environment Variables view in InstallShield, without having the custom code sending the WM_SETTINGCHANGE message. I was able to see the environment variable in the CMD prompt on a Windows 10 (10.0.14393) machine immediately after the installation was completed.
I tried to follow your steps by simply authoring environment variable table. But unfortunately it does not work. Following is my workflow :
- Installed my application. I was able to see environment variable in registry after successful installation. Confirmed that writeenvironmentstring custom action was executed successfully.
Doing action: WriteEnvironmentStrings
Action 17:15:35: WriteEnvironmentStrings. Updating environment strings
Action start 17:15:35: WriteEnvironmentStrings.
WriteEnvironmentStrings: Name: Updating environment strings, Value: , Action
Action ended 17:15:35: WriteEnvironmentStrings. Return value 1.
- Tried to open my application which uses this string as license server location. My application was not able to locate newly added environment variable.
- Closed my application. Opened environment variable dialog from my computer properties. Newly installed environment variable can be seen in this dialog. Clicked OK on dialog to close the dialog. As per publicly available documents closing this dialog sends above mentioned broadcast message.
- Opened my application and it was successfully able to detect license server location.
I would recommend you to try this by invoking an application which uses installed environment variable.
The procedure you've described is right. It does write env. variable in registry but applications are not able to use it until message is broadcasted by wm_settingchange.
Try to search internet and you'll find lot of people struggling with the issue I am facing, specifically with windows 10.
In article at below link Microsoft is saying that environment variable will be propagated after issuing wm_settingchange command.
Can you point me to the document in installshield site where its specified that custom action writeenvironmentstrings executes wm_settingchange ?
I also created a C++ console application that just reads my environment variable using the GetEnvironmentVariable API. It just worked like a charm on my Windows 10 box. My application was able to retrieve the value of the environment variable immediately after the installation was completed. Is the unexpected behavior exhibited on all of your Windows 10 machines? Did you test it on any other platforms like Windows 7? To narrow down the issue, I recommend that you create a setup just installing an environment variable from scratch as well as you write a small application just reading the environment variable, and test it on a clean machine. My C++ code is as simple as below:
DWORD dwSize = 255;
GetEnvironmentVariable(_T("MyEnvVar2"), szEnvValue, dwSize);
MessageBox(NULL, szEnvValue, _T("MyEnvVar2"), MB_OK);
For more details about the WriteEnvironmentStrings action, click the link below:
I checked on Windows 7 and in Windows 7 the environment variable is picked correctly by my application.
So this issue is specific to Windows 10. It seems that in Windows 10 the msi is not able to propagate the addition of env. variables.