Building Customized Input Windows in WiX: Step-by-Step Instructions for Developers

Building Customized Input Windows in WiX: Step-by-Step Instructions for Developers

Donald Lv12

Building Customized Input Windows in WiX: Step-by-Step Instructions for Developers

Versus

Inno SetupInno SetupWiX ToolsetWiX ToolsetInstallShieldInstallShieldMSIX Packaging ToolMSIX Packaging Tool

icon subscribe mail

Check your inbox and confirm the
subscription

Exclusive NewsletterExclusive Newsletter

Exclusive NewsletterExclusive Newsletter

Get the latest WiX insights direct to your inbox. Subscribe now!

Disclaimer: This post includes affiliate links

If you click on a link and make a purchase, I may receive a commission at no extra cost to you.

How to create a custom dialog in WiX for user input

Written by Renato Ivanescu · June 15th, 2023

During the installation process, user input dialogs play a crucial role by prompting users to provide necessary input. This feature is widely utilized in setup packages as it allows users to provide feedback, and it ensures proper installation and configuration of the software. Additionally, it allows you to store valuable information on the local machine for future use.

Let’s say you have an application, and you want to create an installer package that collects information from the user.

In this tutorial, we’ll show you how to create a custom dialog to let the user provide input. We’ll set it up so that it gets saved in a txt file on the local machine after installing the application.

To achieve this, let’s now directly follow the steps outlined in the upcoming sections.

How to add the setup project?

To add the setup project for your application, go to FileNewProject. From the templates list, choose Setup Project for Wix.

Setup Project for Wix

NoteKeep in mind that you need to have the WiX extension added to Visual Studio to find the template. Check this tutorial to see how to add it. There, you’ll also find how to add the deployable files once the Setup Project is created.

https://techidaily.com

Once you add the WiX extension and the deployable files, you have to edit the Product.wxs file and add the next line to reference the UI element we will use in this tutorial.

<Product Id = “*” … >

Copy

How to create the installer dialogs?

Now, we are ready to create the dialogs for our installer package. A dialog is a Windows Installer XML file. We will create two dialogs for our installer package:

  • A welcome dialog → SetupDlg.wxs
  • A dialog for the user input → InputDlg.wxs

To create a dialog, follow the next steps:

  1. Right-click on the Setup ProjectAddNew Item.
  2. Go to the WiX section and choose Installer File.
  3. Name it and click the Add button.

create the installer dialogs

After you create the two dialogs, you should find them in the Solution Explorer under the Setup Project.

Solution Explorer

How to customize the installer dialogs?

Once the installer dialogs are created, you have to add the controls.

1. The welcome dialog from our example includes:

- Static texts

- Two buttons: Cancel (cancel the setup) and Next (proceed to the next dialog)

customize the installer dialogs

https://techidaily.com

For this dialog, you can use the following code.

Copy

2. The input dialog includes:

- Static texts

- Two edit boxes for the user input

- Two buttons: Cancel (cancel the installer) and Install (will start installing the application)

input dialog

https://techidaily.com

For this dialog, add the code below.

1 1

Copy

How to save the user input in a txt file?

Now, we have to take the information from the input dialog and save it in the txt file. For this, we will use a custom action. To create it, follow the steps:

1. Go to FilesNewProject and search for C# Custom Action Project for WiX.

save the user input in a txt file

2. Next, add the following code to create the custom action:

public class CustomActions

    [CustomAction]
    public static ActionResult SaveUserInput(Session session)

        string email = session["EMAIL"];
        string password = session["PASSWORD"];
        string appdataPath = "C:\\Users\\Caphyon";
        if (!Directory.Exists(appdataPath + "\\UserData"))
            Directory.CreateDirectory(appdataPath + "\\UserData");
        File.WriteAllText(appdataPath + "\\UserData\\InputInfo.txt", email + "," + password);
        return ActionResult.Success;

Copy

As you can see, in order to store the user information, the custom action uses the Property attribute values of the emailTextBox and passwordTextBox control elements. The collected information will be written to a text file called InputInfo.txt and saved in the directory C:\Users\Caphyon\UserData.

3. After creating the custom action, you need to reference it in the Setup Project.

To do this, right-click on the Setup ProjectAddReference. In the Add Reference dialog, go to the Projects tab and select the custom action that you created previously. Press the Add button and then the Ok button.

reference it in the Setup Project

https://techidaily.com

Build and install the project

After completing all the above steps, all you have to do is build the project and run the installer package.

Enter the data into the text fields you added to the input dialog and click on the install button. After the installation is complete, you should be able to locate the text file that contains the information you entered in the text boxes.

Conclusion

Designing user input dialogs in WiX can be challenging, particularly for complex scenarios like client-type applications. These cases often involve gathering and storing essential information, such as server address, port number, and firewall settings, in the registry. Editing the .wxs files to incorporate all the controls and create custom actions can be time-consuming.

A more streamlined and effective approach is to leverage a GUI-based tool. Advanced Installer provides an intuitive graphical user interface that simplifies the process of adding controls to dialogs. You can conveniently configure the controls directly from the user interface, saving you valuable time and effort.

Advanced Installer #1 alternative to the WiX Toolset

We decided to focus on our main goal to save precious time of our developers.

HANS-LEO TEULINGS
PHD – CEO, NEUROSCRIPT, LLC

You might find useful:

https://techidaily.com

Get the most from packaging with Advanced Installer

Try the 30-day fully-featured edition absolutely free!

Download Free Trial

No credit card required

Also read:

  • Title: Building Customized Input Windows in WiX: Step-by-Step Instructions for Developers
  • Author: Donald
  • Created at : 2024-09-26 16:30:04
  • Updated at : 2024-10-03 18:47:41
  • Link: https://some-tips.techidaily.com/building-customized-input-windows-in-wix-step-by-step-instructions-for-developers/
  • License: This work is licensed under CC BY-NC-SA 4.0.