Precautions for Windows Service Programming

Source: Internet
Author: User

Recently, due to work needs, I have to write Windows Service programming, but I haven't written it before. I collected relevant information on the Internet and found some problems. I would like to share with you the hope that you will not take this path again.

1. well writtenArticleThere are "programming methods for Windows Services" and 《Write Windows Services in C LanguageProgram.

2. If you want to use the examples in the above two articles, be sure to create a new project andCodePaste it. Otherwise, the service cannot be started. I analyzed the main reason because there is no "stdafx. H" file automatically generated by VC, even if you copy one from another place, it seems useless, you must create your own project.

3. After compiling any program in the above two articles, we will return to the console. Create a service. Enter the command: SC create service name binpath = filepath. (Note that there is a space before "filepath" and "=". If no space exists, you cannot create a service. In this case, the service is created but not run. You can run the service in multiple ways. In the "run" dialog box, enter services. MSC, find the "service name" We just created, right-click it, and choose start. If everything is normal, then our application will start running. Do not create a service name, our application will run. This is an error.

4. debug the service program. There are n debugging methods, but I only have one. Open windbg, select File-> attatch to a process or (F6), and find our service application name. Then you can debug the service program as you debug a general program.

If you have any questions, please contact us. Thank you!

 

Related Article

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.