Windows Develop Bookmark and Share   
 index > ClickOnce and Setup & Deployment Projects > How do I pass command line args to a custom application?
 

How do I pass command line args to a custom application?

Using VS2008. I have a Setup and Deployment project that uses a custom action to launch a small WinForms app to register the software and verify the license. I want to allow a quiet install via the command line for admin installs, but need to pass arguments to the WinForms app that runs from the custom action. Is this possible?

something like this:

setup.msi /quiet /myarg1 myargvalue /myarg2 myargvalue
to cause:
CustomActionWinforms.exe /myarg1 myargvalue /myarg2 myargvalue

KnightKap  Tuesday, August 04, 2009 12:22 AM

Hi KnightKap,

Thank you for your reply!

For .exe custom action, we need to use the Arguments property of the custom action to pass arguments. The following MSDN document has the detailed information:
http://msdn.microsoft.com/en-us/library/wawddahe(VS.80).aspx

Wheninstalling the MSI package, use the public propertyname in the command line. In your scenario, the public properties are "USER" and "PASS" rather than "user" and "pass".

To summary, set the following text in the Arguments property of the custom action:
user="[USER]" pass="[PASS]"

Use the following command line to install the MSI package:
msiexec /i setupname.msi USER="user name" PASS="***"

Please try my suggestion and let me know the result.

Sincerely,
Linda Liu
MSDN Subscriber Support in Forum

If you have any feedback on our support, please contact msdnmg@microsoft.com


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Marked As Answer byKnightKap Friday, August 07, 2009 3:29 PM
  •  
Linda Liu  Thursday, August 06, 2009 4:06 AM

Hi KnightKap,

You can use a custom public property to pass parameters from command line to your custom actions.

To do this, select the custom action in the Custom Action Editor and set the CustomActionData property in the Properties window to a publicproperty.If the custom action is an installation component (ProjectInstaller class), the CustomActionData property takes a format of /name=value; otherwise, there are not format requirements.

For example, you can set the CustomActionData property to /Message=[MESSAGE] in Properties window. Then the command line can be the following:
msiexec /i setupname.msi MESSAGE="hello world"

For more information on CustomActionData property, please read the following MSDN document:
http://msdn.microsoft.com/en-us/library/2w2fhwzz(VS.80).aspx

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
MSDN Subscriber Support in Forum

If you have any feedback on our support, please contact msdnmg@microsoft.com


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Linda Liu  Tuesday, August 04, 2009 8:16 AM
Linda,

Thanks for the quick response.

My custom action is a stand alone exe. More specifically, it is the primary output of one of the projects that gets installed by the msi.

If that app can take an agrument like this: "c:\myapp.exe /u=[username] /p=[password]", then all I need to do is add "/u=[username] /p=[password]" to the custom action data then run msiexec /i setupname.msi u="user" p="pass" and the installer will launch the exe with the correct arguments?

Correct?

KnightKap  Tuesday, August 04, 2009 8:46 PM
Ok, I have tried several variations of this and it does not seem to work...

Do I need to do anything in the custom actions command line argument property as well?

My custom action executable reads for these command line arguments:

        Dim args As String() = Environment.GetCommandLineArgs
        Dim user As String = ""
        Dim pass As String = ""
        If args.Length > 1 Then
            Dim s As String = ""
            For Each arg As String In args
                If Microsoft.VisualBasic.Left(arg, 4) = "user" Then
                    user = Mid(arg, 6)
                If Microsoft.VisualBasic.Left(arg, 4) = "pass" Then
                    pass = Mid(arg, 6)
                End If
            Next

This is what's in the CustomActionData property for the custom action that launches the exe:

/user=[USER] /pass=[PASS]


I have nothing in the arguments property.

But the exe is not being passed the arguments when it runs using this command:

misexec /i setup.msi user=MyUsername pass=MyPassword

???
  • Edited byKnightKap Wednesday, August 05, 2009 5:38 PMcorrection...
  •  
KnightKap  Wednesday, August 05, 2009 5:35 PM

Hi KnightKap,

Thank you for your reply!

For .exe custom action, we need to use the Arguments property of the custom action to pass arguments. The following MSDN document has the detailed information:
http://msdn.microsoft.com/en-us/library/wawddahe(VS.80).aspx

Wheninstalling the MSI package, use the public propertyname in the command line. In your scenario, the public properties are "USER" and "PASS" rather than "user" and "pass".

To summary, set the following text in the Arguments property of the custom action:
user="[USER]" pass="[PASS]"

Use the following command line to install the MSI package:
msiexec /i setupname.msi USER="user name" PASS="***"

Please try my suggestion and let me know the result.

Sincerely,
Linda Liu
MSDN Subscriber Support in Forum

If you have any feedback on our support, please contact msdnmg@microsoft.com


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Marked As Answer byKnightKap Friday, August 07, 2009 3:29 PM
  •  
Linda Liu  Thursday, August 06, 2009 4:06 AM
Thanks Linda. That seems to have worked perfectly...
KnightKap  Friday, August 07, 2009 3:29 PM

You can use google to search for other answers

Custom Search

More Threads

• Still having trouble signing assemblies in VS2005 Beta 2
• Deploying a Win Form via Web Server
• ClickOnce and NGen
• CAS Debuging
• ScheduleReboot
• Setup and Deployment - detect previously installed application, remove and install or update application?
• Problem running Setup MSI from C# project on x86 machines, but it works on x64 machines.
• ClickOnce and command line (Query String)
• Installing a winforms app with a SQL Server db
• ClickOnce and Dotfuscator