ReactOS 0.4.15-dev-7924-g5949c20
umode.c
Go to the documentation of this file.
1#include "DriverTester.h"
2
3
6 LPCWSTR lpPathName)
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}
54
55BOOL
56StartDriver(LPCWSTR lpDriverName)
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}
92
93BOOL
94StopDriver(LPCWSTR lpDriverName)
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}
133
134BOOL
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}
#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 int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define L(x)
Definition: ntvdm.h:50
#define err(...)
SC_HANDLE hSCManager
Definition: sc.c:12
BOOL WINAPI DeleteService(SC_HANDLE hService)
Definition: scm.c:921
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2068
BOOL WINAPI ControlService(SC_HANDLE hService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:622
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2160
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 StartServiceW(SC_HANDLE hService, DWORD dwNumServiceArgs, LPCWSTR *lpServiceArgVectors)
Definition: scm.c:2980
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
SERVICE_STATUS serviceStatus
Definition: tftpd.cpp:63
BOOL RegisterDriver(LPCWSTR lpDriverName, LPCWSTR lpPathName)
Definition: umode.c:5
BOOL StartDriver(LPCWSTR lpDriverName)
Definition: umode.c:56
BOOL StopDriver(LPCWSTR lpDriverName)
Definition: umode.c:94
BOOL UnregisterDriver(LPCWSTR lpDriverName)
Definition: umode.c:135
#define wprintf(...)
Definition: whoami.c:18
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_SERVICE_ALREADY_RUNNING
Definition: winerror.h:607
#define ERROR_SERVICE_MARKED_FOR_DELETE
Definition: winerror.h:623
#define ERROR_SERVICE_NOT_ACTIVE
Definition: winerror.h:613
#define ERROR_SERVICE_EXISTS
Definition: winerror.h:624
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#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
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185