CTS – Your Technology Partner

3 Ways to Make Your WiX Installer Work For You

Written by Nelson Hearn on March 29, 2016

Ah, the WiX toolset, a myriad of XML, pining for the attentions of .msi and setup enthusiasts everywhere. After becoming the standard for producing Microsoft installers, WiX has attempted to supply documentation and forums in order to provide the means necessary to create any needed installer. After a recent project, I found myself wishing I had a quick resource on how to perform some actions within the WiX Toolset. Without further ado, here are 3 things to make your setup easier.

1. Put things in the registry
Placing stuff in the registry — it seems so simple. Use the registry to hold your configuration values, custom settings, or even your mom’s broccoli and cheese recipes. WiX actually allows us to do this using the RegistryValue tag.
(Yeah, I could do that recipe.)

Okay, time for an explanation.

The important pieces here are the Component tag, the RegistryKey tag, and, of course, the RegistryValue tag. Our component needs to have a unique ID and a GUID. The RegistryKey basically lets you know where your registry value will be located. In this case, you want it under HKLM (HK_LOCAL_MACHINE) with the Software/Microsoft/MyProduct directory structure. The RegistryValue tag is the information for the specific entry into the registry that you want to make. You can set the visible name of the registry entry, its type, its value (which can also be a default value if not set), and whether it is the KeyPath (where the program is actually installed on the machine). After you’ve set up your necessary information, you now have to make sure that the installer actually puts your items in the registry. This is accomplished by placing a ComponentRef tag within a Feature tag.

(Hide the super special recipe!)

The concept is pretty basic. Just make sure that your ComponentRef ID matches the ID you set to your Component tag above, and you’re all set.

2. Pull things from the registry
You remember that stuff you just put in the registry? You might need to find it on uninstalls, future re-installs, repairs, or Thursday night dinners.

“How do I do this?” I’m glad you asked!

WiX allows you to do a depth search of the registry for the specific items you are looking for.  Set up a property and say, “You know, I’d really like for this property to contain my mom’s favorite broccoli and cheese recipe that I conveniently stored in the registry while my install is running.”

That’s really all there is to it. The RegistrySearch tag will insert the value from the registry based on the information that you put into the registry earlier. You set the Root, Key, and Name attributes to what you want, and set the Type attribute to “raw” to get the exact text/value that is stored in the registry. If the search doesn’t return any values, the property will not be set.

3. Add in your own modal dialog
Do you want to make sure your custom entry fields are not empty before proceeding with your custom installation? I know I do. Unfortunately, data validation is not really bundled into the WiX Toolset. You’ll have to implement your own kind of alert modal dialog in order to ensure that your users plug text into your labored-over text boxes. The good news is that it’s not too painful.

The first thing you have to do is create your custom error message dialog. Inside of your UI tag, add a new Dialog element and create a nice little Modal.
(Awww, how cute!)

This is just a generic WiX dialog that has been set up to be about a quarter of the size of my normal installation dialogs. One important portion of this dialog is the Publish Event for the OK button. You want this dialog to close on a button press, not shut down the installer since this is a simple validation check. The EndDialog even works just fine for this.  Now, you need to actually show your ErrorDialog when a validation problem occurs.

For me, I don’t want to install the application unless I have Mom’s Delicious Never to be Beaten Broccoli and Cheese Recipe. Here’s my custom setup dialog.WIX3
(Oh I will know if it’s Mom’s recipe or not…)

The saving grace here is the SpawnDialog event. Normally, when you go through an install sequence, you’ll be using NewDialog everywhere. This spawns a new dialog in place of the previous dialog. The SpawnDialog event, however, does just what you would think. It creates a child dialog that controls focus while retaining the state of the previous dialog. Now, when you close your ErrorDialog by pressing OK, you will be dropped right back into MyDlg so that you can fix your validation error!

(That’ll do WiX, that will do.)

There, that wasn’t so bad, was it? The WiX Toolset has some hitches here and there, but the community can help to solve any problems that you may face.

Now go get cooking!