Quick setup and debugging of Windows Services (C # illustration)

Source: Internet
Author: User
Directory

I,What is a Windows service?

2. Create a Windows Service andInstall/uninstall the batch.

3. debug the Windows service.

Body

1. What is a Windows service?

A: Microsoft Windows Services (formerly NT Services) enable you to create executable applications that can run for a long time in their own Windows sessions.Program. These services can be automatically started when the computer is started. They can be paused and restarted without displaying any user interface. This makes the service very suitable for use on the server, or any time, in order not to affect other users working on the same computer, it needs to be used for a long time to run the function. You can also run the service in a security context different from the logon user's specific user account or default computer account.

 

2. Create a Windows service.

Open: Visual Studio 2010 => New => project => Windows service,

Right-click the generated service1.cs File View and choose => Add Installer =>GeneratedOn the projectinstaller. CS view page, set the startup method and Windows Service name in serviceinstaller1,

Then, in setting the account information of serviceprocessinstaller1, select "Local System",

So far, the installation program and framework have been set up, and then on the onstart of service1.csCodeWrite your own business code in the view,

 

Now, the complete Windows service has been created.

The batch code for installing the service:

"% SystemRoot % \ Microsoft. NET \ framework \ v4.0.30319 \ installutil.exe"F: \ XXX \ xxx.exe Net start"Service name"

Batch code for uninstalling a service:

 
Net stop"Service name""% SystemRoot % \ Microsoft. NET \ framework \ v4.0.30319 \ installutil.exe"/U F: \ XXX \ xxx.exe

 

3. debug the Windows service.

In the Visual Studio 2010 toolbar, choose tools> attach to process => click OK, and select the name of the service to be debugged in the list. Click Add to debug the service. In the program, you only need to press F9 to debug it. Note that the Windows Service version must be consistent.


 

 

End

Windows service is actually very simple. Sort it out for the people you need. If it is useful, click support. Thank you.

 

 

 

 

 

 

 

 

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.