Setup and Deployment : Custom Action to Capture User Input

Purpose

Users are allowed to pass Product Key while installing in .msi. During that we want to capture it for registration to avoid piracy.

Challenges

When we use “Customer Information” dialog in “Start” action, it has “SerialNumberTemplate”. But capturing information from there is really tough as mentioned in the article https://support.microsoft.com/kb/253683/en-us. So we have to use the “TextBoxes” dialog and get the data from there.

How

For sample test, I have created on Windows Forms Application “Deployment_SerialNumber”. There I have added InstallerClass called “InstallHelper.cs” with the below code

[RunInstaller(true)]

public partial class InstallerHelp : Installer

{

public override void Install(IDictionary stateSaver)

{

base.Install(stateSaver);

string strKey = Context.Parameters["KeyValue"];

string sPath = @"c:\Test.txt";

if (File.Exists(sPath))

File.Delete(sPath);

File.WriteAllText(sPath, strKey);

}

}

Now I moved to Setup and Deployment Project which is in the same Solution. Added the Primary Output under Application Folder of File System. Pointed the Windows Application “Deployment_SerialNumber”.

image

Then from the Visual Studio menu I have moved to User Interface of Setup project.

image

Then in the “Start” section I have added TextBoxes(A) and placed between “Installation Folder” and “Confirm Installation”.

image

In the property window I made the other two text boxes to invisible.

image

Then moved to “Custom Actions” by VS menu,

image

Then under “Install” added the Project where I have the InstallHelper.cs class.

image

Then we have added the “Custom Action Data” to pass the user input through parameter. That is the catch and because of this we can capture it through string strKey = Context.Parameters["KeyValue"];

Notice the Property and the code. Both has “KeyValue”

image

One caution, The value you pass here cannot be with a space, it will fail (because you are passing parameter).

Namoskar!!!