WixBroadcastSettingChange #200

Merged
merged 3 commits into from Mar 15, 2015

Projects

None yet

3 participants

@barnson
Member
barnson commented Feb 4, 2015

Add WixBroadcastSettingChange and WixBroadcastEnvironmentChange custom
actions to WixUtilExtension.

barnson added some commits Feb 4, 2015
@barnson barnson WixBroadcastSettingChange
Add WixBroadcastSettingChange and WixBroadcastEnvironmentChange custom
actions to WixUtilExtension.
eae181e
@barnson barnson Escape underscores 14e5cbd
@heaths heaths commented on an outdated diff Mar 6, 2015
src/chm/documents/customactions/wixsettingchange.html.md
@@ -0,0 +1,37 @@
+---
+title: WixBroadcastSettingChange and WixBroadcastEnvironmentChange Custom Actions
+layout: documentation
+after: using_standard_customactions
+---
+
+# WixBroadcastSettingChange and WixBroadcastEnvironmentChange Custom Actions
+
+The WixBroadcastSettingChange and WixBroadcastEnvironmentChange custom actions are immediate custom actions that send a WM\_SETTINGCHANGE message to all top-level windows indicating that settings have changed. WixBroadcastSettingChange indicates that unspecified settings have changed. WixBroadcastEnvironmentChange indicates that environment variables have changed.
+
+Other programs are supposed to listen for WM\_SETTINGCHANGE and update any internal state with the new setting.
@heaths
heaths Mar 6, 2015 Contributor

I wouldn't say "are supposed to". I would say something like "Other programs can listen...". They don't have to if they don't care. Most don't handle it.

@heaths heaths commented on an outdated diff Mar 6, 2015
src/chm/documents/customactions/wixsettingchange.html.md
@@ -0,0 +1,37 @@
+---
+title: WixBroadcastSettingChange and WixBroadcastEnvironmentChange Custom Actions
+layout: documentation
+after: using_standard_customactions
+---
+
+# WixBroadcastSettingChange and WixBroadcastEnvironmentChange Custom Actions
+
+The WixBroadcastSettingChange and WixBroadcastEnvironmentChange custom actions are immediate custom actions that send a WM\_SETTINGCHANGE message to all top-level windows indicating that settings have changed. WixBroadcastSettingChange indicates that unspecified settings have changed. WixBroadcastEnvironmentChange indicates that environment variables have changed.
+
+Other programs are supposed to listen for WM\_SETTINGCHANGE and update any internal state with the new setting.
+
+Windows Installer itself sends the WM\_SETTINGCHANGE message for settings it changes while processing an MSI package but cannot do so for changes a package makes via custom action. We've also received reports that Windows Installer does not reliably send WM\_SETTINGCHANGE for environment variable changes.
@heaths
heaths Mar 6, 2015 Contributor

"We've also received reports..." sounds like we're making conjectures. It's actually documented why on my blog and confirmed from the Installer team (Carolyn, IIRC): WM_SETTINGCHANGE is not sent when a reboot is pending (whether from the current MSI or before it).

@heaths heaths commented on the diff Mar 6, 2015
src/chm/documents/customactions/wixsettingchange.html.md
+
+If you are using Votive you can add the extension using the Add Reference dialog:
+
+1. Open your Votive project in Visual Studio
+1. Right click on your project in Solution Explorer and select Add Reference...
+1. Select the **WixUtilExtension.dll** assembly from the list and click Add
+1. Close the Add Reference dialog
+
+## Step 2: Add a reference to the WixBroadcastSettingChange or WixBroadcastEnvironmentChange custom actions
+
+To add a reference to the WixBroadcastSettingChange or WixBroadcastEnvironmentChange custom actions, include one of the following elements in your WiX setup authoring:
+
+ <CustomActionRef Id="WixBroadcastSettingChange" />
+ <CustomActionRef Id="WixBroadcastEnvironmentChange" />
+
+This will cause WiX to add the custom action to your MSI and schedule it immediately after the <a href="http://msdn.microsoft.com/library/aa369505.aspx" target="_blank">InstallFinalize</a> standard action.
@heaths
heaths Mar 6, 2015 Contributor

Does the link render correctly? Not typical for markdown files.

@barnson
barnson Mar 9, 2015 Member

Of course. Markdown doesn't support opening links in new windows.

@heaths heaths commented on the diff Mar 6, 2015
src/ext/ca/wixca/dll/BroadcastSettingChange.cpp
+
+/********************************************************************
+WixBroadcastSettingChange
+
+ Send WM_SETTINGCHANGE message to all top-level windows indicating
+ that unspecified settings have changed.
+********************************************************************/
+extern "C" UINT __stdcall WixBroadcastSettingChange(
+ __in MSIHANDLE hInstall
+ )
+{
+ HRESULT hr = WcaInitialize(hInstall, "WixBroadcastSettingChange");
+ ExitOnFailure(hr, "failed to initialize WixBroadcastSettingChange");
+
+ // best effort; ignore failures
+ ::SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE, NULL, NULL, SMTO_ABORTIFHUNG, 1000, NULL);
@heaths
heaths Mar 6, 2015 Contributor

Why not PostMessage for async broadcasting? Also, since this is immediate it is subject to integrity levels. Maybe this should be scheduled last before InstallFinalize as a commit CA so it's elevated.

@robmen
robmen Mar 15, 2015 Member

Documentation for WM_SETTINGCHANGE says use ::SendMessageTimeout(). Seems reasonable given available information.

@robmen robmen merged commit 5c7ee3d into wixtoolset:develop Mar 15, 2015
@barnson barnson deleted the barnson:BroadcastSettingChange.1 branch Mar 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment