forked from topotam/ppldump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.c
57 lines (53 loc) · 1.37 KB
/
service.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "service.h"
BOOL LoadDriver(
PCHAR szDriverPath
)
{
SC_HANDLE ServiceMan = NULL;
SC_HANDLE ServicePtr = NULL;
BOOL boolRetVal = FALSE;
ServiceMan = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
if ( ServiceMan != NULL ) {
ServicePtr = CreateServiceA(ServiceMan, SVC_NAME, SVC_NAME,
SERVICE_START | DELETE | SERVICE_STOP,
SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START,
SERVICE_ERROR_IGNORE, szDriverPath, NULL,
NULL, NULL, NULL, NULL);
if ( ServicePtr != NULL ) {
StartService(ServicePtr, 0, NULL);
CloseServiceHandle(ServicePtr);
boolRetVal = TRUE;
};
CloseServiceHandle(ServiceMan);
};
return boolRetVal;
};
BOOL UnloadDriver(
VOID
)
{
SC_HANDLE ServiceMan = NULL;
SC_HANDLE ServicePtr = NULL;
SERVICE_STATUS ServiceStat = { 0 };
BOOL boolRetVal = FALSE;
ServiceMan = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
if ( ServiceMan != NULL ) {
ServicePtr = OpenServiceA(ServiceMan,
SVC_NAME, SERVICE_STOP | DELETE);
if ( ServicePtr != NULL ) {
ControlService
(
ServicePtr,
SERVICE_CONTROL_STOP,
&ServiceStat
);
DeleteService(ServicePtr);
CloseServiceHandle(ServicePtr);
boolRetVal = TRUE;
};
CloseServiceHandle(ServiceMan);
};
return boolRetVal;
};