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”.
Then from the Visual Studio menu I have moved to User Interface of Setup project.
Then in the “Start” section I have added TextBoxes(A) and placed between “Installation Folder” and “Confirm Installation”.
In the property window I made the other two text boxes to invisible.
Then moved to “Custom Actions” by VS menu,
Then under “Install” added the Project where I have the InstallHelper.cs class.
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”
One caution, The value you pass here cannot be with a space, it will fail (because you are passing parameter).
Namoskar!!!
Comments
Anonymous
May 21, 2009
PingBack from http://microsoft-sharepoint.simplynetdev.com/setup-and-deployment-custom-action-to-capture-user-input/Anonymous
July 09, 2009
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.comAnonymous
March 30, 2010
Useful stuff... Well Explained!Anonymous
May 26, 2011
Very useful, finally one i understood ;)Anonymous
February 02, 2012
Thanks ! Very nice, Step by Step explanation, made my life easier !Anonymous
February 26, 2012
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 KasivelAnonymous
March 06, 2014
The comment has been removedAnonymous
June 06, 2014
hi, is it possible to valid the textbox? something likes the Next just be enabled only when the EDITA4 meets some criteria. thanksAnonymous
June 14, 2014
Excellent write-up. Very useful in my implementation. Thank you.Anonymous
July 02, 2014
thanks for these correct explanations........Anonymous
November 19, 2014
you can pass a value with a space, using a CustomActionData such as this /Param1="[EDITA2]" /Param2="[TARGETDIR]" the quotes and the final backslash-quote are importantAnonymous
March 26, 2016
if (null == adobe) { System.Windows.Forms.MessageBox.Show("Please, Install Adobe reader 9.0 or above."); try { base.Rollback(stateSaver); // error msg showing when install software- passs value in stateSaver } catch { base.Rollback(stateSaver); } }Anonymous
March 26, 2016
RegistryKey adobe = Registry.LocalMachine.OpenSubKey("Software").OpenSubKey("Adobe"); if (null == adobe) { System.Windows.Forms.MessageBox.Show("Please, Install Adobe reader 9.0 or above."); try { base.Rollback(stateSaver); // error showing when install software because adobe reader not found in pc. } catch { base.Rollback(stateSaver); } }