ReactOS 0.4.15-dev-7712-gbbbcd8e
umode.c File Reference
#include "DriverTester.h"
Include dependency graph for umode.c:

Go to the source code of this file.

Functions

BOOL RegisterDriver (LPCWSTR lpDriverName, LPCWSTR lpPathName)
 
BOOL StartDriver (LPCWSTR lpDriverName)
 
BOOL StopDriver (LPCWSTR lpDriverName)
 
BOOL UnregisterDriver (LPCWSTR lpDriverName)
 

Function Documentation

◆ RegisterDriver()

BOOL RegisterDriver ( LPCWSTR  lpDriverName,
LPCWSTR  lpPathName 
)

Definition at line 5 of file umode.c.

7{
8 SC_HANDLE hSCManager;
9 SC_HANDLE hService;
10
12 NULL,
14 if (!hSCManager)
15 return FALSE;
16
17retry:
18 hService = CreateServiceW(hSCManager,
19 lpDriverName,
20 lpDriverName,
25 lpPathName,
26 NULL,
27 NULL,
28 NULL,
29 NULL,
30 NULL);
31
32 if (hService)
33 {
34 CloseServiceHandle(hService);
36 return TRUE;
37 }
38 else
39 {
41
43 {
45 goto retry;
46 }
47
49
50 // return TRUE if the driver is already registered
51 return (err == ERROR_SERVICE_EXISTS);
52 }
53}
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define DRIVER_NAME
Definition: ext2fs.h:136
unsigned long DWORD
Definition: ntddk_ex.h:95
#define err(...)
SC_HANDLE hSCManager
Definition: sc.c:12
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2068
SC_HANDLE WINAPI CreateServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, LPCWSTR lpDisplayName, DWORD dwDesiredAccess, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCWSTR lpBinaryPathName, LPCWSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCWSTR lpDependencies, LPCWSTR lpServiceStartName, LPCWSTR lpPassword)
Definition: scm.c:812
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
BOOL StopDriver(LPCWSTR lpDriverName)
Definition: umode.c:94
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_SERVICE_MARKED_FOR_DELETE
Definition: winerror.h:623
#define ERROR_SERVICE_EXISTS
Definition: winerror.h:624
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
#define SC_MANAGER_ALL_ACCESS
Definition: winsvc.h:13
#define SERVICE_DEMAND_START
Definition: cmtypes.h:978
#define SERVICE_KERNEL_DRIVER
Definition: cmtypes.h:953
#define SERVICE_ERROR_NORMAL
Definition: cmtypes.h:982

Referenced by Initialize().

◆ StartDriver()

BOOL StartDriver ( LPCWSTR  lpDriverName)

Definition at line 56 of file umode.c.

57{
58 SC_HANDLE hSCManager;
59 SC_HANDLE hService;
60 BOOL bRet;
61
63 NULL,
65 if (!hSCManager)
66 return FALSE;
67
68 hService = OpenServiceW(hSCManager,
69 lpDriverName,
71 if (!hService)
72 {
74 return FALSE;
75 }
76
77 bRet = StartServiceW(hService, 0, NULL);
78 if (!bRet)
79 {
81 {
82 wprintf(L"%s.sys already running\n", DRIVER_NAME);
83 bRet = TRUE;
84 }
85 }
86
87 CloseServiceHandle(hService);
89
90 return bRet;
91}
unsigned int BOOL
Definition: ntddk_ex.h:94
#define L(x)
Definition: ntvdm.h:50
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2160
BOOL WINAPI StartServiceW(SC_HANDLE hService, DWORD dwNumServiceArgs, LPCWSTR *lpServiceArgVectors)
Definition: scm.c:2980
#define wprintf(...)
Definition: whoami.c:18
#define ERROR_SERVICE_ALREADY_RUNNING
Definition: winerror.h:607

◆ StopDriver()

BOOL StopDriver ( LPCWSTR  lpDriverName)

Definition at line 94 of file umode.c.

95{
96 SC_HANDLE hSCManager;
97 SC_HANDLE hService;
99 BOOL bRet;
100
102 NULL,
104 if (!hSCManager)
105 return FALSE;
106
107 hService = OpenServiceW(hSCManager,
108 lpDriverName,
110 if (!hService)
111 {
113 return FALSE;
114 }
115
116 bRet = ControlService(hService,
119 if (!bRet)
120 {
122 {
123 wprintf(L"%s.sys wasn't running\n", DRIVER_NAME);
124 bRet = TRUE;
125 }
126 }
127
128 CloseServiceHandle(hService);
130
131 return bRet;
132}
BOOL WINAPI ControlService(SC_HANDLE hService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:622
SERVICE_STATUS serviceStatus
Definition: tftpd.cpp:63
#define ERROR_SERVICE_NOT_ACTIVE
Definition: winerror.h:613
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36

Referenced by RegisterDriver().

◆ UnregisterDriver()

BOOL UnregisterDriver ( LPCWSTR  lpDriverName)

Definition at line 135 of file umode.c.

136{
137 SC_HANDLE hService;
138 SC_HANDLE hSCManager;
139 BOOL bRet;
140
142 NULL,
144 if (!hSCManager)
145 return FALSE;
146
147 hService = OpenServiceW(hSCManager,
148 lpDriverName,
150 if (!hService)
151 {
153 return FALSE;
154 }
155
156 bRet = DeleteService(hService);
157
158 CloseServiceHandle(hService);
160
161 return bRet;
162}
BOOL WINAPI DeleteService(SC_HANDLE hService)
Definition: scm.c:921

Referenced by UndocumentedMethod(), Uninitialize(), and UsermodeMethod().