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