1 /****************************************************************************
3 * SciTech Display Doctor
5 * Copyright (C) 1991-2001 SciTech Software, Inc.
8 * ======================================================================
9 * |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW|
11 * |This copyrighted computer code is a proprietary trade secret of |
12 * |SciTech Software, Inc., located at 505 Wall Street, Chico, CA 95928 |
13 * |USA (www.scitechsoft.com). ANY UNAUTHORIZED POSSESSION, USE, |
14 * |VIEWING, COPYING, MODIFICATION OR DISSEMINATION OF THIS CODE IS |
15 * |STRICTLY PROHIBITED BY LAW. Unless you have current, express |
16 * |written authorization from SciTech to possess or use this code, you |
17 * |may be subject to civil and/or criminal penalties. |
19 * |If you received this code in error or you would like to report |
20 * |improper use, please immediately contact SciTech Software, Inc. at |
23 * |REMOVAL OR MODIFICATION OF THIS HEADER IS STRICTLY PROHIBITED BY LAW|
24 * ======================================================================
27 * Environment: Windows NT, Windows 2K or Windows XP.
29 * Description: Main module to do the installation of the SDD and GLDirect
30 * device driver components under Windows NT/2K/XP.
32 ****************************************************************************/
35 #include "win32/oshdr.h"
37 /*----------------------------- Implementation ----------------------------*/
39 /****************************************************************************
41 szDriverName - Actual name of the driver to install in the system
42 szServiceName - Name of the service to create
43 szLoadGroup - Load group for the driver (NULL for normal drivers)
44 dwServiceType - Service type to create
47 True on success, false on failure.
50 This function does all the work to install the driver into the system.
51 The driver is not however activated; for that you must use the Start_SddFilt
53 ****************************************************************************/
54 ulong PMAPI PM_installService(
55 const char *szDriverName,
56 const char *szServiceName,
57 const char *szLoadGroup,
61 SC_HANDLE driverHandle;
62 char szDriverPath[MAX_PATH];
64 char keyPath[MAX_PATH];
67 /* Obtain a handle to the service control manager requesting all access */
68 if ((scmHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) == NULL)
69 return GetLastError();
71 /* Find the path to the driver in system directory */
72 GetSystemDirectory(szDriverPath, sizeof(szDriverPath));
73 strcat(szDriverPath, "\\drivers\\");
74 strcat(szDriverPath, szDriverName);
76 /* Create the service with the Service Control Manager. */
77 driverHandle = CreateService(scmHandle,
91 /* Check to see if the driver could actually be installed. */
93 status = GetLastError();
94 CloseServiceHandle(scmHandle);
98 /* Get a handle to the key for driver so that it can be altered in the */
100 strcpy(keyPath, "SYSTEM\\CurrentControlSet\\Services\\");
101 strcat(keyPath, szServiceName);
102 if ((status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,keyPath,0,KEY_ALL_ACCESS,&key)) != ERROR_SUCCESS) {
103 /* A problem has occured. Delete the service so that it is not installed. */
104 status = GetLastError();
105 DeleteService(driverHandle);
106 CloseServiceHandle(driverHandle);
107 CloseServiceHandle(scmHandle);
111 /* Delete the ImagePath value in the newly created key so that the */
112 /* system looks for the driver in the normal location. */
113 if ((status = RegDeleteValue(key, "ImagePath")) != ERROR_SUCCESS) {
114 /* A problem has occurred. Delete the service so that it is not */
115 /* installed and will not try to start. */
117 DeleteService(driverHandle);
118 CloseServiceHandle(driverHandle);
119 CloseServiceHandle(scmHandle);
123 /* Clean up and exit */
125 CloseServiceHandle(driverHandle);
126 CloseServiceHandle(scmHandle);
127 return ERROR_SUCCESS;
130 /****************************************************************************
132 szServiceName - Name of the service to start
135 True on success, false on failure.
138 This function is used to start the specified service and make it active.
139 ****************************************************************************/
140 ulong PMAPI PM_startService(
141 const char *szServiceName)
144 SC_HANDLE driverHandle;
145 SERVICE_STATUS serviceStatus;
148 /* Obtain a handle to the service control manager requesting all access */
149 if ((scmHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) == NULL)
150 return GetLastError();
152 /* Open the service with the Service Control Manager. */
153 if ((driverHandle = OpenService(scmHandle,szServiceName,SERVICE_ALL_ACCESS)) == NULL) {
154 status = GetLastError();
155 CloseServiceHandle(scmHandle);
159 /* Start the service */
160 if (!StartService(driverHandle,0,NULL)) {
161 status = GetLastError();
162 CloseServiceHandle(driverHandle);
163 CloseServiceHandle(scmHandle);
167 /* Query the service to make sure it is there */
168 if (!QueryServiceStatus(driverHandle,&serviceStatus)) {
169 status = GetLastError();
170 CloseServiceHandle(driverHandle);
171 CloseServiceHandle(scmHandle);
174 CloseServiceHandle(driverHandle);
175 CloseServiceHandle(scmHandle);
176 return ERROR_SUCCESS;
179 /****************************************************************************
181 szServiceName - Name of the service to stop
184 True on success, false on failure.
187 This function is used to stop the specified service and disable it.
188 ****************************************************************************/
189 ulong PMAPI PM_stopService(
190 const char *szServiceName)
193 SC_HANDLE driverHandle;
194 SERVICE_STATUS serviceStatus;
197 /* Obtain a handle to the service control manager requesting all access */
198 if ((scmHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) == NULL)
199 return GetLastError();
201 /* Open the service with the Service Control Manager. */
202 if ((driverHandle = OpenService(scmHandle,szServiceName,SERVICE_ALL_ACCESS)) == NULL) {
203 status = GetLastError();
204 CloseServiceHandle(scmHandle);
208 /* Stop the service from running */
209 if (!ControlService(driverHandle, SERVICE_CONTROL_STOP, &serviceStatus)) {
210 status = GetLastError();
211 CloseServiceHandle(driverHandle);
212 CloseServiceHandle(scmHandle);
215 CloseServiceHandle(driverHandle);
216 CloseServiceHandle(scmHandle);
217 return ERROR_SUCCESS;
220 /****************************************************************************
222 szServiceName - Name of the service to remove
225 True on success, false on failure.
228 This function is used to remove a service completely from the system.
229 ****************************************************************************/
230 ulong PMAPI PM_removeService(
231 const char *szServiceName)
234 SC_HANDLE driverHandle;
237 /* Obtain a handle to the service control manager requesting all access */
238 if ((scmHandle = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) == NULL)
239 return GetLastError();
241 /* Open the service with the Service Control Manager. */
242 if ((driverHandle = OpenService(scmHandle,szServiceName,SERVICE_ALL_ACCESS)) == NULL) {
243 status = GetLastError();
244 CloseServiceHandle(scmHandle);
248 /* Remove the service */
249 if (!DeleteService(driverHandle)) {
250 status = GetLastError();
251 CloseServiceHandle(driverHandle);
252 CloseServiceHandle(scmHandle);
255 CloseServiceHandle(driverHandle);
256 CloseServiceHandle(scmHandle);
257 return ERROR_SUCCESS;