C # Create an installation, uninstall a deployment program

Source: Internet
Author: User

Share 3:

Requirements: Install and encapsulate the application that has been developed, that is, create the installation, uninstall the deployment program;

Analysis: The development of the program is to use different people on different machines, in order to make different machines use the software needs to see the program installation package, and ensure that the installation package must contain the operation of the software required to run the environment;

Specific operation:

1. Create a new project in VS2010, select: Install and deploy with other project types, Setup Wizard, and then determine;

2. The interface defaults to the file system, the left and right sides; After clicking on the application folder in the right side, select Add File, add the executable file that needs to be packaged and the related component class library, etc.

3. Right-click the application folder on the left to open the Properties dialog box and remove the "[manufacture]" in the path to "DefaultLocation" in the properties (otherwise the installer default directory is C:\programm file\ your user name \ Install solution name)

4. Add a shortcut to the execution program, select Execute program, right-click the Generate shortcut, you can rename it and cut it to the left side of the "User's" program menu "or user desktop (so that after the installation is complete, the shortcut will appear in the menu or desktop)

5. (important) Select the project name, right-click the property, and in the property page, select Prerequisites, Check the "Create Installer for Installing Prerequisites", select your prerequisites in the check box, and tick "download prerequisites from the same location as my application" (Important: Tick " Download prerequisites from the same location as my application (D) "In fact, it means that when you tick, when you build the installation project, you will have the components that you checked in the prerequisites list in the path of your installation project. (The system automatically completes, this is good, do not need you to download components))

To this, basically complete the production, click "Build-and build Solution", you can find in debug Setup.exe or "project name. msi"

6. There are two ways to create an uninstall feature:

Method One:

A. When adding an application, you need to add a Msiexec.exe (can be renamed to Uninstall.exe), just like the executing program (this file is under the C:\window\system32 folder);

B. (important) Select Msiexec.exe, you need to set the Aguement property value for the executor enter "/x {ProductCode}" (There are spaces between/X and {ProductCode}). The ProductCode value can be found in the project properties (that is, the registry number for that installer)

This uninstall program has a drawback: when the installation package computer system if it is 64-bit, then if the installation program is completed, on the 32-bit computer This uninstall function, it will not work (because Msiexec.exe is 64-bit). To solve this problem, you only have to create an application and call the Msiexec.exe in the system directly.

Method Two:

Create a new console program and add the following code to the Main method: string sysroot = System.Environment.SystemDirectory; System.Diagnostics.Process.Start (sysroot+ "\\msiexec.exe", "/x {ProductCode (this value was obtained in the Setup Project properties)}/qr");

Click Build, get the. exe file in the Bin folder, and add it to the application in the Installer project (as you did later). This makes it possible to directly invoke the Msiexec.exe program in the computer system.

At this point, basically complete the setup program, as for the other settings, you can set the relevant parameters in the properties, you can also customize the installation interface in the view and so on.

C # Create an installation, uninstall a deployment program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.