Setup and Deployment : Custom Action to Capture User Input

Setup and Deployment : Custom Action to Capture User Input

  • Comments 9

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 http://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!!!

 

Leave a Comment
  • Please add 2 and 1 and type the answer here:
  • Post
  • PingBack from http://microsoft-sharepoint.simplynetdev.com/setup-and-deployment-custom-action-to-capture-user-input/

  • hi, tnx for this! i do have a couple of questions more though, if you could respond to my email, i'd be glad to discuss my inquiry, and your help would be so much appreciated! thank you!

    exavier666@gmail.com

  • Useful stuff...

    Well Explained!

  • Very useful, finally one i understood ;)

  • Thanks ! Very nice, Step by Step explanation, made my life easier !

  • public override void Install(IDictionary stateSaver)

       {      

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

            if(strKey=="123")

            {

           base.Install(stateSaver);

             }

           else

             {

               ///Show message to user , keycode that you entered is wrong one Please enter the correct One

            }

       }

    Can I do like this .How can i do this  ? Please Any one Help me out.

    With Thanks ,

    Ananthi Kasivel

  • Hi, thnx for this great explanation. But is there any way to check the textbox value before installation? I mean whenever we click the next button in the dialog box?

  • Excellent write-up.  Very useful in my implementation.  Thank you.

  • thanks for these correct explanations........

Page 1 of 1 (9 items)