Add an automatic installation package for C # Windows Services]

Source: Internet
Author: User
Add installer for C # Windows Service

First, you must create a Windows service project. Everyone should know how to do this (Leave a message asking me if I don't understand it), and then "add installer" to the service ", 1: (this step is exactly the same as registering with installutil)

(Figure 1)

After adding the package, a serviceprocessinstal1 and serviceinstaller1 will be displayed. If you have two services in a project, there will be two serviceinstaller classes, 2:


(Figure 2)

Figure 3 shows the attribute page of serviceprocessinstal1, where account refers to the account used to run the service. If it is only used locally, you can select LocalSystem (Local System), which is the highest local permission, you can also choose to interact with the desktop. If you want security, select the one that suits you.

(Figure 3)

Figure 4 shows the attribute page of serviceinstaller2. displayname is the service name displayed in the Windows Service Manager. desciption is the description of the service. The following servicename is the internal name of the service. The most important thing is the following starttype, which refers to the Service Startup method, which is automatic, manual, or disabled.

(Figure 4)

Next is the focus of today's lecture. Click "file"> "add"> "new project" (5)

(Figure 5)

Select "other project type"> "installation and deployment" (6)

(Figure 6)

After the project is created, right-click the newly created installation project and choose View> File System (7)


(Figure 7)

In this case, the file system attribute is opened. As you can see, there are three file systems on the left of the screen, because we are a Windows service program and do not need to place icons in the Start Menu or desktop, so right-click "application folder"> "add"> "project output" (8)

(Figure 8)

In the displayed dialog box, select "primary output" and "Release XXX". This is determined by the Project attributes. Generally, select release any CPU. (9)

(Figure 9)

The system will automatically put the project output file, that is, the Windows Service Program's exe file and all referenced class library files in the middle of the box. To facilitate the installation, we add installutil.exe and two self-written batch files. The add method is similar to the above, just change "project output" to "File ".
Result 10:

(Figure 10)

Next, configure the installation process and let the installer automatically install and uninstall the Windows service.

Right-click to install the project, select "View"-& gt; "Custom operations", 11:

(Figure 11)

The window on the left is changed to the custom operation view, right-click "Install"-> "add custom operation" (Figure 12), and in the displayed dialog box, select the "Application folder", and then select the installutil.exefile (Figure 13) in it. After the installation is completed, the branch of installutil.exe is displayed. Click it. On the properties page on the right, set arguments = "your Windows service file name" and 14 (note that a space is required before the file name)

(Figure 12)

(Figure 13)

(Figure 14)

In the same example, installutil.exe is also available in the submission and dismounting processes. However, in the attribute page, set arguments = "-u your Windows service file name". In this way, the installer can automatically install, register, and uninstall Windows Services.

[Amendment]

->

In fact, as long as the installation, submission, rollback, and uninstallation Add the main output of the project, it can also achieve the automatic registration/uninstallation of the service function, and does not rely on installutil.exe (15)

<-

This step is problematic only after multiple tests!

After installutil.exe is completed, the service can be automatically installed only after installation, submission, rollback, and uninstallation are added to the main output of the project. In addition, the sequence is to initialize installutil.exe first, and then add the main output of the project !!!

 

(Figure 15)

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.