Reverse Intro [Windows]

Foreword

This article is a brief introduction to windows services, including basic concepts of logic and write basic code.

Brief introduction

Service Controller (SCM):

Control services to install, remove, start, stop, and so on. . .
For all the system management services (including the driver).
SCM manages service programs and device drivers database system already installed.
Stored in the database, the system was installed which services, detailed information for each service (start information, security attributes, control interfaces, etc.)

Service Category:

1. The service application (user mode service need to comply with SCM Interface Specification)
2 kernel driver service routine

Function:

Service main function (serviceMain):

1. The code that executes when the service starts entrance, by the SCM calls

Service control handler:
1. registration control processing function
to register a service control handler to SCM

2. The control processing function:
for processing the control request to the SCM service delivery (start, stop, etc.)

Code logic

. 1  // === the Main Function 
2  void main ()
 . 3  {
 . 4      IF (service has been created)
 . 5      {
 . 6          // 1. ServiceMain SCM to register the service master function 
. 7      }
 . 8      the else 
. 9      {
 10          // 1. Sc.exe Create service
 . 11          @ 2. Create the API service 
12      }
 13  }
 14  
15  // === service master function 
16  void WINAPI ServiceMain (DWORD argc, LPTSTR * the argv)
 . 17  {
 18 is      // 1. registration service control handler
 19      / /2. Set the operating state of the service 
20  }
 21 is  
22 is  // === service control handler 
23 is  void WINAPI serviceCtrlHandler (DWORD the Opcode)
 24  {
 25      Switch (the Opcode)
 26 is      {
 27          Case XXX:   // Start 
28          Case XXXX: // stop 
29          Case XXXXX: // other 
30      }
 31 }

Guess you like

Origin www.cnblogs.com/SunsetR/p/11978005.html