Windows Installer has been integrated since vs2005 (not used in earlier versions of vs2005). You can use the vs tool to easily package and release your programs;
1. First, create your application concurrency release‑release. Take mytest.exe as an example;
2. Create an installation project
3. Add your application to the installation package. Right-click the application folder and choose "add"> "file"> "application mytest.exe ".
If your application is a Windows service, you also need to add the installation operation in the Custom edit operation, install-add custom operation-application folder-select your service;
4. A simple installation package is complete, isn't it easy. However, there are still many things we need to set up in practical applications: for example, creating a shortcut on the desktop or creating a shortcut in the Start Menu, you may also need to set the application installation folder and application attributes. These are not described here.
5. Some children's shoes may need to be asked, How can I uninstall the installation program? Let's give an example:
Create a window application named uninstall and add the following code in the load event of form1:
Private void from_load (Object sender, eventargs E)
{
This. Hide ();
If (MessageBox. Show ("delete mytest", "Uninstall prompt", messageboxbuttons. okcancel, messageboxicon. Question, messageboxdefaultbutton. button1) = dialogresult. OK)
{
System. Diagnostics. process. Start ("msiexec", "/X {741a0689-eb4a-43a0-adf9-f545476b3aff}/QR ");
}
Application. Exit ();
}
Here we use the msiexec component in the window to uninstall it. The following string of parameters is the productcode in your installation program (go to your installation project properties to find it );
You can also use the console project to complete the corresponding functions, but there is a black window that is not friendly.
6. If you need to start the application after installation, continue:
Create a new class library, add an installer class, and then rewrite onafterinstall, directly to the Code:
/// <Summary>
/// Rewrite the function after installation.
/// Automatically start the installed program after installation
/// </Summary>
/// <Param name = "savedstate"> </param>
Protected override void onafterinstall (idictionary savedstate)
{
Base. onafterinstall (savedstate );
// Start the service
Try
{
Servicecontroller SC = new servicecontroller ();
SC
. Servicename = "service name ";
SC. Start ();
}
Catch (system. invalidoperationexception)
{}
// Start the application
Assembly ASM = assembly. getexecutingassembly ();
String Path = ASM. Location. Remove (ASM. Location. lastindexof ("\") + "\\";
System. Diagnostics. process. Start (path + "\ mytest.exe ");
}
Right-click the installation project and choose "add project output"> "main output" from the shortcut menu. Select the installer component library you just created and choose "Custom operation Editor"> "Install" (right-click) -Add custom operations-select your installer output. Compilation and generation.