none
Passing a parameter to msi installer by command line

    Question

  • <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} -->

    I am trying to pass a parameter to the msi through the command line in C#.

     

    Here it is:   msiexec /I setup.msi /qn USER=Joe

     

    I created an installer class that writes to a registry key.  I have setup a Custom Action for Install that has the code to write to a registry key in it. 

     

    If I hardcode the value for the registry key, that value is written correctly to the registry key in the custom action.  However, I am not able to retrieve my value from the command line (USER=Joe).  I would much appreciate any help.

     

    CustomActionData Property for Custom Action for Install:    /user="USERNAME"

     

    Here is my code in the Installer Class:

     

            public override void Install(IDictionary savedState)

            {

                base.Install(savedState);

                // string username = “Joe”   (This writes correctly to the registry key if hardcoded)


                string username = ??? (I want to be able to retrieve Joe from command line here)

     

                // Code to write to registry key using the username value above

            }

     

    How do I retrieve the USER=Joe from the msiexec command line above?

     

    Thanks,

    bsmengen

    Thursday, May 20, 2010 7:16 PM

Answers

  • First, you don't need code to write that to the registry. Just create a registry item in the IDE and give it the value [USER] if USER is the name of the property on the command line AND the property name must be upper-case.

    So what you would pass to your custom action is /user=[USER]

    and it's in the Context.Parameters dictionary in the Install method.  I'd stay away from potentially common names like USERNAME because there is already a standard property of that name and you will conflict.


    Phil Wilson
    • Marked as answer by Helen Zhou Thursday, May 27, 2010 3:04 AM
    Thursday, May 20, 2010 10:26 PM
    Moderator
  • 1 Yes.

    2. PASSEDUSER=Joe. But setup projects generate internal custom actions ("CustomTextA_SetProperty_EDIT1") that nullify the property, so you pass it on the command line and ... the setup project clears it. This seems unnecessary to me, but anyway it's why passing it on the command line doesn't work.

    3. Context.Parameters is a standard .NET dictionary, nothing weird, just the usual (key, value) pair, so something like Context.Parameters['"user"] will get you the corresponding value.


    Phil Wilson
    • Marked as answer by Helen Zhou Thursday, May 27, 2010 3:04 AM
    Friday, May 21, 2010 10:55 PM
    Moderator

All replies

  • First, you don't need code to write that to the registry. Just create a registry item in the IDE and give it the value [USER] if USER is the name of the property on the command line AND the property name must be upper-case.

    So what you would pass to your custom action is /user=[USER]

    and it's in the Context.Parameters dictionary in the Install method.  I'd stay away from potentially common names like USERNAME because there is already a standard property of that name and you will conflict.


    Phil Wilson
    • Marked as answer by Helen Zhou Thursday, May 27, 2010 3:04 AM
    Thursday, May 20, 2010 10:26 PM
    Moderator
  • I did create a registry item and it writes to it fine if I get the value from a textbox [TEXTBOX1] on a User Interface form.  My problem is I want to do a install where the user doesn't have to input anything.  I know the username and want to pass it in on the command line for the msiexec.

    msiexec /I setup.msi /qn PASSEDUSER=Joe

    1)  So would the CustomActionData property of the custom action be  /appuser=[PASSEDUSER]?


    I know that the value of the registry item would be "[TEXTBOX1]" when using a textbox on a User Interface form.

    That works and the registry is updated.  However, I haven't been able to get it to work when trying to reference the PASSEDUSER parameter from the command line in the value of the registry item.

    2)  What would I enter in the value of the registry item for passed parameter on the command line of the msiexec?

     

    3)  If I can't reference PASSEDUSER in the registry item, can you please show me the code on how to use the Context.Parameters dictionary in the Install method.

    Here is my code in the Installer Class:

             public override void Install(IDictionary savedState)

            {

                base.Install(savedState);

                ??  Code to reference Context.Parameters dictionary

            }

    Thanks,

    Bob E

    Friday, May 21, 2010 12:41 PM
  • 1 Yes.

    2. PASSEDUSER=Joe. But setup projects generate internal custom actions ("CustomTextA_SetProperty_EDIT1") that nullify the property, so you pass it on the command line and ... the setup project clears it. This seems unnecessary to me, but anyway it's why passing it on the command line doesn't work.

    3. Context.Parameters is a standard .NET dictionary, nothing weird, just the usual (key, value) pair, so something like Context.Parameters['"user"] will get you the corresponding value.


    Phil Wilson
    • Marked as answer by Helen Zhou Thursday, May 27, 2010 3:04 AM
    Friday, May 21, 2010 10:55 PM
    Moderator
  • This will solve the problem of having the value reset by the setup:

    https://blogs.msdn.microsoft.com/helloworld/2009/02/06/how-to-add-command-line-support-with-your-msi/

    Friday, February 9, 2018 11:36 AM