Publishing a Windows service using InstallUtil

Source: Internet
Author: User

Methods for publishing Windows service

1, in the default window Service1 right-click Add Install, automatically generate two classes.

2. Modify the properties of the ServiceInstaller1:

a) ServiceName = "FirstService";//Set service name

b) StartType = Automatic;//start mode has three kinds: "Automatic", "manual", "Disabled". In fact, there is also a mode in the "Manage" and "services" of "My Computer": "Automatic (delayed start)"

c) Modifiers=public;

There are also properties, such as "Display Name" in displayname corresponding, "service name" in the corresponding ServiceName, and (name) corresponding, these properties can be modified accordingly

  

3. Set the properties of the ServiceProcessInstaller1 component

1) account = LocalSystem; For maximum permissions This property also includes: LocalService, NetworkService, user (default state, if you use user, you need to provide a username and password when installing), if you need to learn more about this property, you can refer to:

Http://technet.microsoft.com/zh-cn/system.serviceprocess.serviceprocessinstaller.account (vs.90). aspx

2) Modifiers=public;

4, modify the name of the service: Open the ProjectInstaller.Designer.cs file, modify the this.serviceInstaller1.ServiceName corresponding value.

5. Build the solution: Choose Release Mode Right-click Build Solution, then the corresponding path will appear in the MyFirstService.exe file (generated using debug mode does not appear to be installed).

6. Use InstallUtil to install the new Myfirstservice, as follows:

First, open the C:\Windows\Microsoft.NET\Framework64\v4.0.30319 directory and locate the InstallUtil.exe file.

Second, copy the file to the root of your build service.

    

Use the command: in cmd, locate the directory where your service resides (that is, the directory where InstallUtil.exe resides) and install it using the InstallUtil service name. exe.

Four: Use the command: the name of the installutil/u service. EXE, click Run to uninstall the service.

Five: Use the command to open services.msc to find your service.

Here are a few things to keep in mind:

First: The above two "service absolute path" is like: E:\ new Folder \test\myfirstservice\myfirstservice\bin\release\ MyFirstService.exe, in this place to note is: Must choose release under generate solution. The default is to generate solution under Debug.

Second: For window7 users, in the installation process prone to several errors:

    • If you are using a computer that is not logged on with your system administrator's account, the following error will occur. (I have already done the testing), especially in the use of WINDOW7 users need to be aware that the system default is "disabled" mode.

  

    • The second error may be that the service already exists and the following error will occur

  

To avoid this error, we should first take the third step when installing the service (that is, if possible, first uninstall the existing service).

Original reference: Http://www.cnblogs.com/YanPSun/archive/2010/05/22/1741381.html

Publishing a Windows service using InstallUtil

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.