Customize User Interfaces and Pass User Input to Installer Classes

In this article I am going to demonstrate how to customize your MSI install to prompt the user for some information and then pass this information to an installer class.  This can be useful when needing to do something during an install based on the user input. 

There are two key parts to this process the first is the addition of a custom user interface dialog and the second is passing whatever information is entered into the new user interface  to the installer class in order to do something with this information during installation. 

For the sake of simplicity this MSI is going to install an assembly called MySampleAssembly and inside the project we will add an installer class that will take the information the user enters via the newly added user interface and place this information into the event log.  (Once you get the information into the installer class you can do anything you want with it, we are placing it in the event log only to prove that the information was successfully passed in)  

This article assumes some basic understanding of MSI projects, more information can be found on at 

http://www.c-sharpcorner.com/Code/2002/July/BuildnDeployUsingVSNet.asp  

Part One Adding a New User Interface

1. First start a new Set-up project.

2. Next we need to make the modifications to the default user interface settings.  Navigate to the view/Editor/User Interface as shown below. 

This brings up the User Interface editor and displays the default MSI user interface.  You can see that this is broken up into a couple of different sections that are common to all MSI setups. 

3. Next you need to right click on the Start node of the tree view and choose the Add Dialog menu item as shown below: 

This will bring up the Add Dialog menu displaying all of the various user dialogs you can add to the msi.  We are going to add 3 radio buttons to the default user interface that prompts the user for his/her input in regards to what environment the application is being deploy into Dev, Test, or Prod.   This is common issue when building deployment scripts, as we may need to do different things based on the environment we are deploying too.  Select the Radio Buttons (3 buttons) icon as shown below: 

4. An icon representing the radio buttons user dialog should now be displayed in the user interface editor.   By right clicking on this icon and choosing the properties menu item the default properties will be displayed for this user interface item.  Modify all the properties to look like the following: 

 An important thing to notice is the ButtonProperty that is currently set at BUTTON3.   This is the name of our newly added user interface item and ultimately the variable that holds the value that the user has entered when the MSI is run.  In our case the screen we added contains three radio buttons and based on what the user chooses at the time of the install the BUTTON3 variable will hold a 1,2 or 3. 

Part Two: Passing Information to the Installer Class. 

5. Next we need to create a sample assembly and include an installer class in the project that will accept the information input by the user and do something with it.  The addition of the installer class is the same as an earlier article I wrote with one key difference.  If you are not familiar with installer classed you can read an earlier article located here: 

http://www.c-sharpcorner.com/Code/2002/July/UseInstClasses.asp

Creating The Sample Assembly

6. Create a simple assembly and call it mySampleAssembly.

7. Next right click on project name in the solution explorer and choose add new item and double click on the installer class icon. 

8. Now navigate to the installer class and look at the code that is generated for you automatically. You need to override the Install function by adding the following code.

public
 override void Install(System.Collections.IDictionary stateSaver)
{
string myPassedInValue=this.Context.Parameters["TEST"];
//1=DEV 2=TEST 3= PROD
System.Diagnostics.EventLog.WriteEntry
("Button3 value", myPassedInValue); 
}

This does nothing but get a value from the parameter named "TEST" and put it into the eventlog.  

For the sake of simplicity leave all the other classes in the MySampleApp assembly alone and compile the assembly.  You will also need to add a using 

9.  We now need to add this newly compiled assembly to our MSI project that we were working on earlier.  Go back to the MSI project we were working on earlier and click on the View/Editor/File System, which will bring up the file system editor in the msi project.  Right click on the application folder and choose add/File as shown below. 

Navigate to the MySampleApp assembly we just made and add it to the msi project. 

10.  Next choose the View / Editor / Custom Actions menu item, this will bring up the custom action dialog menu as shown below. 

Highlight the install folder and right click on the folder and choose Add Custom Action as shown below.   

Navigate to the assembly we just added to the installer class and click ok as shown here.

This tells the MSI project to run any installer classes that is in the MySampleAssembly assembly. 

Finally, choose the properties of the custom action and modify the properties as shown below. 

Notice in the CustomActionData that we are placing a /TEST=[BUTTON3].  This tells the installer class to pass the value of the Button3 user interface object to the installer class in a parameter named TEST.  In this particular case it is a 1, 2, or 3 that will be passed to the installer class but it could be anything from a database name to a server name that is passed to the installer class.  

11.   Finally, compile and run the msi eventually you should see the new user interface and will place a 1, 2, or 3 into the event log based which radio button you chose. 

In this article I demonstrated how to add a custom dialog to an MSI and take the information received from this newly added dialog and pass it into an installer class.  This can be useful when creating MSI's that need to behave differently based on some user input.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
As an AI language model, I don't use OkHttp myself. However, I can provide you with information on how to use OkHttp as a user. OkHttp is a popular HTTP client library in Java and Android applications. To use OkHttp in your project, you should follow these steps: 1. Add the OkHttp dependency to your project. You can do this by adding the following to your Gradle file: ``` dependencies { implementation 'com.squareup.okhttp3:okhttp:4.9.0' } ``` 2. Create an instance of the OkHttpClient class, which will handle all your HTTP requests. You can customize the client by setting various options, such as timeouts and interceptors. ``` OkHttpClient client = new OkHttpClient.Builder() .connectTimeout(10, TimeUnit.SECONDS) .readTimeout(10, TimeUnit.SECONDS) .build(); ``` 3. Create an HTTP request using the Request class. You can set the URL, headers, and other parameters of the request. ``` Request request = new Request.Builder() .url("https://api.example.com/users") .addHeader("Authorization", "Bearer token") .build(); ``` 4. Send the request using the client's newCall() method, which returns a Call object. You can execute the call synchronously or asynchronously. ``` Call call = client.newCall(request); Response response = call.execute(); ``` 5. Handle the response by accessing the response body, headers, and status code. ``` String responseBody = response.body().string(); int statusCode = response.code(); Headers headers = response.headers(); ``` OkHttp also provides features such as caching, authentication, and connection pooling. You can learn more about these features in the OkHttp documentation.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值