Create and Control Windows services--introduction[level: advanced]

Source: Internet
Author: User
Tags execution
services|window| Advanced Windows Services (formerly known as NT Services) can seem overwhelming and daunting to the uninitiated Because of a vast array of callback functions and long parameter lists. Even though creating services in C + + almost ensures top-notch, the performance complexity factor the might that outweigh. However, with the recent release of the. NET Framework SDK, the complexity of creating and controlling services has Dimin Ished. If development is the essence, the Visual c#.net and the. NET Framework prove invaluable assets.

What you need:
. NET Framework SDK, Windows NT4 or Windows 2000



In this article, I'll demonstrate the necessary steps to create a Windows Service, then explain I-control your Servic E by creating a useful utility this could prove invaluable as you test and debug your service. But the give you some background on Windows Services.

Most of us remember Terminate-and-stay-resident (TSR) programs-ones that remained into memory after being executed but gave Control back to the user. As useful as they were, you faced the occasional compatibility and problem in the environment your ran them in. System architectures inevitably increased in reliability and multitasking capabilities, and the TSRs gave rise to what we n OW call the service.

A Service is A executable that gives the operating system nonintrusive functionality. A service installed and configured to run automatically begins execution before a user logs on to the computer. Some Common uses for services include hardware control and monitoring applications; System-level utility, diagnostic, and reporting tools; and communication software such as a Web or File-system server.

Although a service is a executable, you can ' t start and terminate it through traditional means. The most common way to start one:register it with the service control Manager as a automatic service. This is ensures the service starts as soon as the machine has finished the boot cycle and before a user logs on to the system . You can also start a service manually using the console command NET start <servicename> or through the service Apple T within the Windows Administrative Tools group.

Services also can allow to pause and continue during execution, either manually or programmatically. But providing this functionality are up to the service designer-it ' s not required.

Just as a service doesn ' t start as other executables does, it also can ' t terminate the same way other many can. The service itself generally has no user interface associated with it and so it terminates when the user turns off or restart s the system, or manually stops the service using the Service applet again or with the NET STOP <servicename> Consol e command.

You are must follow special rules while creating a service to get it to run correctly within the system environment. The most important:you must install or register a service within the system it intends to run in. In the other words, the can ' t just run a service by double-clicking to its executable file. Furthermore, a service shouldn ' t provide a user interface. Rather, it should do's reporting with the system event log or performance counters. I ' m not saying services can ' t have a user interface, but the each service was created within in it own Windows station, so ui- Related API calls might not succeed. Finally, a service must support a number of methods I ' ll discuss later to the control's execution life cycle.


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.