ReactOS  0.4.14-dev-608-gd495a4f
umode.c
Go to the documentation of this file.
1 #include "DriverTester.h"
2 
3 
4 BOOL
5 RegisterDriver(LPCWSTR lpDriverName,
6  LPCWSTR lpPathName)
7 {
8  SC_HANDLE hSCManager;
9  SC_HANDLE hService;
10 
12  NULL,
14  if (!hSCManager)
15  return FALSE;
16 
17 retry:
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 
55 BOOL
56 StartDriver(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 
93 BOOL
94 StopDriver(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,
118  &serviceStatus);
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 
134 BOOL
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 StopDriver(LPCWSTR lpDriverName)
Definition: umode.c:94
#define SERVICE_ERROR_NORMAL
Definition: cmtypes.h:980
#define TRUE
Definition: types.h:120
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
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:808
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
#define wprintf(...)
Definition: whoami.c:18
BOOL WINAPI DeleteService(SC_HANDLE hService)
Definition: scm.c:916
#define ERROR_SERVICE_NOT_ACTIVE
Definition: winerror.h:613
BOOL RegisterDriver(LPCWSTR lpDriverName, LPCWSTR lpPathName)
Definition: umode.c:5
unsigned int BOOL
Definition: ntddk_ex.h:94
SC_HANDLE WINAPI OpenServiceW(SC_HANDLE hSCManager, LPCWSTR lpServiceName, DWORD dwDesiredAccess)
Definition: scm.c:2103
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:577
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_SERVICE_MARKED_FOR_DELETE
Definition: winerror.h:623
BOOL WINAPI StartServiceW(SC_HANDLE hService, DWORD dwNumServiceArgs, LPCWSTR *lpServiceArgVectors)
Definition: scm.c:2923
BOOL StartDriver(LPCWSTR lpDriverName)
Definition: umode.c:56
unsigned long DWORD
Definition: ntddk_ex.h:95
SERVICE_STATUS serviceStatus
Definition: tftpd.cpp:63
#define ERROR_SERVICE_EXISTS
Definition: winerror.h:624
static const WCHAR L[]
Definition: oid.c:1250
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2011
#define DRIVER_NAME
Definition: ext2fs.h:136
#define err(...)
SC_HANDLE hSCManager
Definition: sc.c:12
BOOL WINAPI ControlService(SC_HANDLE hService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:619
#define SC_MANAGER_ALL_ACCESS
Definition: winsvc.h:13
BOOL UnregisterDriver(LPCWSTR lpDriverName)
Definition: umode.c:135
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_DEMAND_START
Definition: cmtypes.h:976
#define ERROR_SERVICE_ALREADY_RUNNING
Definition: winerror.h:607
#define SERVICE_KERNEL_DRIVER
Definition: cmtypes.h:951