WIN32 Service Program (i): Create service

Source: Internet
Author: User

There are examples of installation Services in MSDN Installing a service (clickable access), the creation of our services here, and the MSDN example is basically the same. Here are some simple explanations:

Open Control Panel, administrative tools, services. The interface we see that sets up the service is also called the Service Control Manager (SCM).

To create a service with a program, first use the OpenSCManager function to establish a connection to the Service Control Manager and open the specified database. Passes the handle of the specified service Control Manager database returned by the function to the CreateService function. Complete the service creation work. The final effect, after the program runs, in the Service Control Manager, you can see the services we created

The program code is as follows:

1#include <windows.h>2#include <winsvc.h>3#include <stdio.h>4 5 voidinstallservices ();6 7 voidMain ()8 {9 installservices ();Ten } One  A voidinstallservices () - { -     Charname[ -]; the     Charinfo[ $]; -     Charpath[ -]; -  -printf"Service Name:"); + gets (name); -printf"Display Name:"); + gets (info); Aprintf"Program Path:"); at gets (path); -  -Sc_handle Manager =NULL; -Sc_handle Service =NULL; -  -Manager =OpenSCManager (null,null,sc_manager_create_service); in  -     if(Manager = =NULL) to     { +printf"error!\n"); -         return; the     } *  $Service =CreateService (manager,name,info,service_all_access,service_win32_own_process,Panax NotoginsengService_auto_start,service_error_normal,path,0,0,0,0,0); -     if(Service) theprintf"Install success!\n"); +     Else Aprintf"Install falid!\n"); the  + closeservicehandle (service); - Closeservicehandle (manager); $}

Finally we opened the SCM and saw the service we built.

WIN32 Service Program (i): Create service

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.