Reference: http://www.taiwanren.com/blog/article.asp? Id = 8686
1. Use vs to create a Windows Service Project (the Chinese version is Windows Service). After the project directory is created, it is similar:
2. Switch to the design interface of services1.cs and open its Properties tab:
3. click the add installer link on the properties page. For more information, see the reference document. "after that, you will get two file service components and program. CS. to create a service, you must first add a dedicated installation component. This step is also very simple. Select the service component and switch to the design mode. Right-click and choose add installer to generate the installation file, switch to the design mode. here you will see two components: serviceinstaller and processinstaller. There is not much to note here, most of which are about setting the service name, description, and other information, there are only two places to note. one is starttype. There are three options: automatic, manual, and disabled. if You Want To Enable Automatic startup, select automatic once. another attribute that needs to be noted is account. Select User. Generally, select local system."
4. Write your own business logic code
5. Compile the program and install the service. This article provides a better generation script (yourservicename is the name of your own Service): 1 net stop yourservicename
2 copy/y "$ (targetdir)" $ (projectdir) bin"
3 "% SystemRoot % \ Microsoft. NET \ framework \ v2.0.50727 \ installutil.exe"/U $ (projectdir) bin \ $ (targetfilename)
4 "% SystemRoot % \ Microsoft. NET \ framework \ v2.0.50727 \ installutil.exe" $ (projectdir) bin \ $ (targetfilename)
5. Net start yourservicename
6
6. debugging. debugging of services is very troublesome. There are a lot of articles on the Internet. The "process appending" in Visual Studio debugging should be able to meet most of the requirements. if you want to debug the onstart and onstop methods, you need some other methods, which are not described here (I have not understood ).