Windowsservice (Windows Services) development step with demo "Turn"

Source: Internet
Author: User

Turn http://www.cnblogs.com/moretry/p/4149489.html

1. Open VS, create a new project, select Windows Services, then set the directory and project name and click OK.

2, expand Service1 Service file, write Service1.cs class file, not service1[design]. Then modify the OnStart and OnStop methods.

3, write the service code, there is not much to say, the realization of simple writing log function ... Look at the code, if you don't understand, see demo

4. Configure the Windowsservice installation program. Switch to Design view, right-click, the menu appears, click Add Installer.

5. In the Installer interface, select **processinstaller1, and then F4 view properties, account changes to LocalService. Check the **installer1,f4 view properties, description Service description, DisplayName service friendly display name, servicename the name of the service in the system, do not duplicate the system service, guarantee unique, StartType start mode, Select Automatic (self-starter).

6, build the solution, then we start to install the service to the system, F5 direct generation is not possible, will error, here is not demonstrated. We open the cmd Command Prompt window.

We use the. Net Framework Automated Tool InstallUtil.exe installation. First find its directory, my native directory is: C:\Windows\Microsoft.NET\Framework\v4.0.30319

Depending on your PC and the. NET Framework version, switch to the appropriate directory yourself and then execute the CD CD in your directory in the cmd window.

Then execute the Install Service command: InstallUtil.exe the path to your Windows service build. If the path to my service is F:\Work\WindowsService\WindowsService\bin\Debug\WindowsService.exe

The order is: InstallUtil.exe F:\Work\WindowsService\WindowsService\bin\Debug\WindowsService.exe

See this indicates that the service has been installed successfully. Now we go to the computer service to see the services we write. Computer Right-click Management to view Computer Management, and then find the service menu on the left.

We found service items for displayname (Windows Services Demo)

Right-click to start ... We open the log file to see if the service is working properly. , the service runs correctly.

7, uninstall the service, uninstall our development of the service command is: installutil.exe/u service location path

To the end of this Windows service development.

8, Demo:http://files.cnblogs.com/moretry/windowsservicedemo.zip

Windowsservice (Windows Services) development step with demo "Turn"

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.