Complete installation of Windows Services in 10 steps

Source: Internet
Author: User
It may be because it is too lazy to study the installation of a Windows service. Program It took about half a day. I have provided some examples on the Internet, but all of them have been mentioned, making the process too much. I always want to study how to use installutil.exe and its parameters. In fact, to install the Windows Service created under. net, you must first install the. NET Framework on the target machine. For this reason, installutil.exe must already exist on the target machine. Therefore, using Microsoft's silly operations can solve the problem of Windows service installation and uninstallation.

After a while, it is estimated that the Windows service will be used to complete some functions. In order to deepen the impression, I turned back to a Windows service named helloworldservice and used the simplest demo to complete all the operations. The function of this service is to create a helloworld.txt file at startup, and write Hello world in it! Just a few simple letters.

1. Select Visual C #-> Windows service to create a helloworldservice project.

 

2. Use servicename to change the service name to "helloworldservice". This is the name that appears in the Service Management Panel after the service is successfully installed.

3. Change service1.cs to helloworldservice. CS, and write a simpleCodeTo create a file and write "Hello world! "These are classic letters.
 

4. Right-click the design field of helloworldservice. CS and select "add installer" in the pop-up menu.

 

Two controls-serviceprocessinstall and serviceinstaller-are added to the design interface.

Serviceprocessinstall installs an executable file that contains the class that extends servicebase. This class is called by the installation utility (such as installutil.exe) when installing the service application. Here, we mainly modify the attributes of the account. Serviceaccount specifies the service security context, which defines the login type. LocalService An account that acts as a non-privileged user on a local computer and provides anonymous creden。 to all remote servers.
LocalSystem The account used by the Service Control administrator. It has many permissions on the Local Computer and serves as a computer on the network.
NetworkService Provides an account with a wide range of local privileges that provides computer creden。 to all remote servers.
User A specific user-defined account on the network. If you specify a user for the serviceprocessinstaller. Account member, the system prompts you to enter a valid user name and password when installing the service, unless you set the values for the username and password attributes of the serviceprocessinstaller instance.

Serviceinstaller installs a class that extends servicebase to implement services. This class is called by the installation utility when the service application is installed. The starttype attribute is modified here. This value specifies the Service Startup Mode.

Automatic Indicates that the service will be started by (or by) the operating system at system startup. If an automatically started service depends on a manually started service, the manually started service is also automatically started when the system starts.
Disabled Indicates disabling the service so that it cannot be started by users or applications.
Manual Indicates that the service is manually started only by users (using the Service Control Manager) or applications.

5. The above are all objects to be installed/uninstalled in the installation package. The following describes how to use. Net to create an installation package.
You must add an installation project named helloworldsetup in the solution.
6. After adding a project, right-click "application folder" on the default view interface and choose "add"-> "project output". In the displayed window, select "primary output" and click "OK ". 7. The above step defines the content that is finally included in the application folder. Next, we will define other aspects. Right-click a project and choose View> Custom operation. 8. On the following page, right-click "Custom operation" and choose "add custom operation".

 

In the displayed window, double-click "application folder".

 

Select "active output from helloworldservice (activity)" and click "OK".

 

After the selection, you will find that all operations have added the selected items. By doing this, the installer can not only uninstall the program, but also uninstall the service.

9. Right-click the installation project and select generate to publish the installation program normally. After the installation is successful, two files are generated.

 

Copy these two files to the target machine and double-click the helloworldsetup. MSI file to start the installation of services.

After the installation is successful, we will be able to see our dream service programs from the Service Management Panel.
However, when I started it, there was also an episode: The system reported an error. Errors include:

 

You can view the specific error information in the "application" option of the system's "Event Viewer.

 

It turned out to be caused by the Service's permission to operate the file system. Run it back and check that the account of serviceprocessinstaller was set to LocalService in step 1, and changed to LocalSystem. Then re-release the installation program, then re-install the service, and then start, haha, everything is normal!

10. Finally, let's take a look at the results of this Windows Service:

 

conclusion: When you encounter a problem, you must be calm and systematically understand the current transaction, rather than rush to seek success. This efficiency will be relatively low.

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.