C # Add an installer to a Windows Service Program: I have been engaged in Windows Services recently and have gained a lot of experience. I feel that the permissions are definitely much more limited than general programs, but there are also a lot of convenience. For example, the system is not blocked in the background, and user logon is not required. Haha, it's a long journey. Today, let's talk about how to create an installation package for the Windows service. Why install the installation package? Of course it is convenient. You don't need to call InstallUtil every time. Also, it looks more formal.
C # The concept of adding an installer to a Windows service program is not mentioned. Let's take a look at how to do it. 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)
(C # adding and installing a Windows Service Program 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:
(C # adding and installing a Windows Service Program 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.
(C # Windows Service Program addition and installation program figure 3)
Figure 4 shows the attribute page of serviceInstaller2, where DisplayName is the name of the service displayed in the Windows Service Manager, and 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.
(C # adding and installing a Windows Service Program Figure 4)
Next is the focus of today's lecture. Click "file"> "add"> "new project" (5)
(C # Windows Service Program addition and installation program figure 5)
Select "other project type"> "installation and deployment" (6)
(C # Windows Service Program addition and installation program figure 6)
After the project is created, right-click the newly created installation project and choose View> File System (7)
(C # adding and installing a Windows Service Program 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)
(C # Windows Service Program addition and installation program 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)
(C # Windows Service Program addition and installation program 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:
(C # Windows Service Program addition and installation program figure 10)
Next, configure the installation process and let the installer automatically install and uninstall the Windows service.
Right-click the project and choose "View"> "Custom operations". 11:
(C # adding and installing a Windows Service Program figure 11)
The window on the left is changed to the custom operation view, right-click "Install"-> branch of the worker. Click it and set Arguments ="
Your Windows service file name ", 14 (note that you need to leave a space before the file name)
(C # Add and install a Windows Service Program figure 12)
(C # adding and installing a Windows Service Program figure 13)
(C # Windows Service Program addition and installation program figure 14)
In the same example, installutil.exe is also available for submission and dismounting, but arguments = "-U" is set on the property page.
The name of your Windows service file ", so that the installer can automatically install and register and uninstall the Windows service. (15)
(C # Windows Service Program addition and installation program figure 15)
Next, we should compile the Windows Service and installation project at the same time. Right-click solution and select "properties" (16). In the displayed dialog box, click Generate after the installation project. (17)
(C # Windows Service Program addition and installation program figure 16)
(C # adding and installing a Windows Service Program figure 17)
Finally, right-click the solution and select "generate solution". At this time, Vs will compile both projects. Note that the startup sequence of the project must be before the Windows Service Project and after the installation project.