Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get some parameter from user while installing a c# application

I have a C# win form application and I build a "setup" for it by visual studio 2010

my application needs some parameters like username , pass, ip and ...

i want to get these values from user before setup complete and save it to a file to use by my application. but how?

like image 573
Maziar Aboualizadehbehbahani Avatar asked Dec 28 '25 16:12

Maziar Aboualizadehbehbahani


1 Answers

This answer presumes that you are using the Setup Project in Visual Studio. If you aren't edit your question and we can take another look.

To gather user input you need to introduce a new dialog to the installer.

The following steps will bring you to the part of the installer project that will allow you to add new dialogs:

  • In the Solution Explorer menu select the option "User Interface Editor"
  • In the newly opened screen right click on of the options (Install for example) and select "Add Dialog"
  • This displays a range of pre-built user dialogs. You will probably want one of the text box dialogs.

If you want something different you can also create a custom setup dialog. There is a nice code project post on doing this here.


Once you have this information you need to actually access it and use it during installation.

For this you need to add an installer class to your target project (the project you want to install).

In that installer class you can reference the text boxes you created using code like this:

public override void Install(System.Collections.IDictionary stateSaver)
{
    string myPassedInValue=this.Context.Parameters["TEST"];
    //Do what you want with that value - such as storing it as you wanted.
}

This answer is a little bit from 10000 feet - if I went into all the detail I'd end up writing a full article. If you have any sticking points, please ask. Also - have a look at this excellent article on the subject, it should get you most if not all of the way.

like image 169
David Hall Avatar answered Dec 30 '25 04:12

David Hall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!