Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
loaddrv.h File Reference
#include <windows.h>
+ Include dependency graph for loaddrv.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define OKAY   0
 
#define UNEXPECTED_ERROR   9999
 

Functions

DWORD LoadDriverInit (void)
 
void LoadDriverCleanup (void)
 
DWORD DriverInstall (LPSTR, LPSTR)
 
DWORD DriverStart (LPSTR)
 
DWORD DriverStop (LPSTR)
 
DWORD DriverRemove (LPSTR)
 
DWORD DriverStatus (LPSTR)
 
DWORD DriverStartType (LPSTR, DWORD)
 

Macro Definition Documentation

◆ OKAY

#define OKAY   0

◆ UNEXPECTED_ERROR

#define UNEXPECTED_ERROR   9999

Function Documentation

◆ DriverInstall()

DWORD DriverInstall ( LPSTR  lpPath,
LPSTR  lpDriver 
)

195 {
196 BOOL dwStatus = OKAY;
197 SC_HANDLE hService = NULL;
198
199 // add to service control manager's database
200 if ((hService = CreateService(hSCMan, lpDriver,
201 lpDriver, SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER,
202 SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, lpPath,
203 NULL, NULL, NULL, NULL, NULL)) == NULL)
204 dwStatus = GetLastError();
205 else CloseServiceHandle(hService);
206
207 return dwStatus;
208} // DriverInstall
SC_HANDLE hSCMan
Definition loaddrv.c:17
#define OKAY
Definition loaddrv.h:6

References hSCMan, and OKAY.

Referenced by main().

+ Here is the caller graph for this function:

◆ DriverRemove()

DWORD DriverRemove ( LPSTR  lpDriver)

251{
252 BOOL dwStatus = OKAY;
253 SC_HANDLE hService = NULL;
254
255 // get a handle to the service
256 if ((hService = OpenService(hSCMan, lpDriver,
257 SERVICE_ALL_ACCESS)) != NULL)
258 { // remove the driver
259 if (!DeleteService(hService))
260 dwStatus = GetLastError();
261 } else dwStatus = GetLastError();
262
263 if (hService != NULL) CloseServiceHandle(hService);
264 return dwStatus;
265} // DriverRemove

References hSCMan, and OKAY.

Referenced by main().

+ Here is the caller graph for this function:

◆ DriverStart()

DWORD DriverStart ( LPSTR  lpDriver)

211 {
212 BOOL dwStatus = OKAY;
213 SC_HANDLE hService = NULL;
214
215 // get a handle to the service
216 if ((hService = OpenService(hSCMan, lpDriver,
217 SERVICE_ALL_ACCESS)) != NULL)
218 {
219 // start the driver
220 if (!StartService(hService, 0, NULL))
221 dwStatus = GetLastError();
222 } else dwStatus = GetLastError();
223
224 if (hService != NULL) CloseServiceHandle(hService);
225 return dwStatus;
226} // DriverStart

References hSCMan, and OKAY.

Referenced by main().

+ Here is the caller graph for this function:

◆ DriverStartType()

DWORD DriverStartType ( LPSTR  lpDriver,
DWORD  dwStartType 
)

388 {
389 BOOL dwStatus = OKAY;
390 SC_HANDLE hService = NULL;
391
392 SC_LOCK sclLock;
393 LPQUERY_SERVICE_LOCK_STATUS lpqslsBuf;
394 DWORD dwBytesNeeded;
395
396 // Need to acquire database lock before reconfiguring.
397 sclLock = LockServiceDatabase(hSCMan);
398
399 // If the database cannot be locked, report the details.
400 if (sclLock == NULL) {
401 // Exit if the database is not locked by another process.
402 if (GetLastError() == ERROR_SERVICE_DATABASE_LOCKED) {
403
404 // Allocate a buffer to get details about the lock.
405 lpqslsBuf = (LPQUERY_SERVICE_LOCK_STATUS) LocalAlloc(
406 LPTR, sizeof(QUERY_SERVICE_LOCK_STATUS)+256);
407 if (lpqslsBuf != NULL) {
408 // Get and print the lock status information.
409 if (QueryServiceLockStatus(
410 hSCMan,
411 lpqslsBuf,
412 sizeof(QUERY_SERVICE_LOCK_STATUS)+256,
413 &dwBytesNeeded) )
414 {
415 if (lpqslsBuf->fIsLocked) {
416 printf("Locked by: %s, duration: %ld seconds\n",
417 lpqslsBuf->lpLockOwner,
418 lpqslsBuf->dwLockDuration
419 );
420 } else {
421 printf("No longer locked\n");
422 }
423 }
424 LocalFree(lpqslsBuf);
425 }
426 }
427 dwStatus = GetLastError();
428 } else {
429 // The database is locked, so it is safe to make changes.
430 // Open a handle to the service.
431 hService = OpenService(
432 hSCMan, // SCManager database
433 lpDriver, // name of service
434 SERVICE_CHANGE_CONFIG
435 ); // need CHANGE access
436 if (hService != NULL) {
437 // Make the changes.
438 if (!ChangeServiceConfig(
439 hService, // handle of service
440 SERVICE_NO_CHANGE, // service type: no change
441 dwStartType, // change service start type
442 SERVICE_NO_CHANGE, // error control: no change
443 NULL, // binary path: no change
444 NULL, // load order group: no change
445 NULL, // tag ID: no change
446 NULL, // dependencies: no change
447 NULL, // account name: no change
448 NULL, // password: no change
449 NULL) ) // display name: no change
450 {
451 dwStatus = GetLastError();
452 }
453 }
454 // Release the database lock.
455 UnlockServiceDatabase(sclLock);
456 }
457
458 if (hService != NULL) CloseServiceHandle(hService);
459 return dwStatus;
460} // DriverStartType

References hSCMan, and OKAY.

Referenced by main().

+ Here is the caller graph for this function:

◆ DriverStatus()

DWORD DriverStatus ( LPSTR  lpDriver)


270 {
271 BOOL dwStatus = OKAY;
272 SC_HANDLE hService = NULL;
273 DWORD dwBytesNeeded;
274
275 // get a handle to the service
276 if ((hService = OpenService(hSCMan, lpDriver,
277 SERVICE_ALL_ACCESS)) != NULL)
278 {
279 LPQUERY_SERVICE_CONFIG lpqscBuf;
280 //~ LPSERVICE_DESCRIPTION lpqscBuf2;
281 // Allocate a buffer for the configuration information.
282 if ((lpqscBuf = (LPQUERY_SERVICE_CONFIG) LocalAlloc(
283 LPTR, 4096)) != NULL)
284 {
285 //~ if ((lpqscBuf2 = (LPSERVICE_DESCRIPTION) LocalAlloc(
286 //~ LPTR, 4096)) != NULL)
287 {
288 // Get the configuration information.
289 if (QueryServiceConfig(
290 hService,
291 lpqscBuf,
292 4096,
293 &dwBytesNeeded) //&&
294 //~ QueryServiceConfig2(
295 //~ hService,
296 //~ SERVICE_CONFIG_DESCRIPTION,
297 //~ lpqscBuf2,
298 //~ 4096,
299 //~ &dwBytesNeeded
300 )
301 {
302 // Print the configuration information.
303 printf("Type: [0x%02lx] ", lpqscBuf->dwServiceType);
304 switch (lpqscBuf->dwServiceType) {
305 case SERVICE_WIN32_OWN_PROCESS:
306 printf("The service runs in its own process.");
307 break;
308 case SERVICE_WIN32_SHARE_PROCESS:
309 printf("The service shares a process with other services.");
310 break;
311 case SERVICE_KERNEL_DRIVER:
312 printf("Kernel driver.");
313 break;
314 case SERVICE_FILE_SYSTEM_DRIVER:
315 printf("File system driver.");
316 break;
317 case SERVICE_INTERACTIVE_PROCESS:
318 printf("The service can interact with the desktop.");
319 break;
320 default:
321 printf("Unknown type.");
322 }
323 printf("\nStart Type: [0x%02lx] ", lpqscBuf->dwStartType);
324 switch (lpqscBuf->dwStartType) {
325 case SERVICE_BOOT_START:
326 printf("Boot");
327 break;
328 case SERVICE_SYSTEM_START:
329 printf("System");
330 break;
331 case SERVICE_AUTO_START:
332 printf("Automatic");
333 break;
334 case SERVICE_DEMAND_START:
335 printf("Manual");
336 break;
337 case SERVICE_DISABLED:
338 printf("Disabled");
339 break;
340 default:
341 printf("Unknown.");
342 }
343 printf("\nError Control: [0x%02lx] ", lpqscBuf->dwErrorControl);
344 switch (lpqscBuf->dwErrorControl) {
345 case SERVICE_ERROR_IGNORE:
346 printf("IGNORE: Ignore.");
347 break;
348 case SERVICE_ERROR_NORMAL:
349 printf("NORMAL: Display a message box.");
350 break;
351 case SERVICE_ERROR_SEVERE:
352 printf("SEVERE: Restart with last-known-good config.");
353 break;
354 case SERVICE_ERROR_CRITICAL:
355 printf("CRITICAL: Restart w/ last-known-good config.");
356 break;
357 default:
358 printf("Unknown.");
359 }
360 printf("\nBinary path: %s\n", lpqscBuf->lpBinaryPathName);
361
362 if (lpqscBuf->lpLoadOrderGroup != NULL)
363 printf("Load order grp: %s\n", lpqscBuf->lpLoadOrderGroup);
364 if (lpqscBuf->dwTagId != 0)
365 printf("Tag ID: %ld\n", lpqscBuf->dwTagId);
366 if (lpqscBuf->lpDependencies != NULL)
367 printf("Dependencies: %s\n", lpqscBuf->lpDependencies);
368 if (lpqscBuf->lpServiceStartName != NULL)
369 printf("Start Name: %s\n", lpqscBuf->lpServiceStartName);
370 //~ if (lpqscBuf2->lpDescription != NULL)
371 //~ printf("Description: %s\n", lpqscBuf2->lpDescription);
372 }
373 //~ LocalFree(lpqscBuf2);
374 }
375 LocalFree(lpqscBuf);
376 } else {
377 dwStatus = GetLastError();
378 }
379 } else {
380 dwStatus = GetLastError();
381 }
382
383 if (hService != NULL) CloseServiceHandle(hService);
384 return dwStatus;
385} // DriverStatus

References hSCMan, and OKAY.

Referenced by main().

+ Here is the caller graph for this function:

◆ DriverStop()

DWORD DriverStop ( LPSTR  lpDriver)

230{
231 BOOL dwStatus = OKAY;
232 SC_HANDLE hService = NULL;
233 SERVICE_STATUS serviceStatus;
234
235 // get a handle to the service
236 if ((hService = OpenService(hSCMan, lpDriver,
237 SERVICE_ALL_ACCESS)) != NULL)
238 {
239 // stop the driver
240 if (!ControlService(hService, SERVICE_CONTROL_STOP,
241 &serviceStatus))
242 dwStatus = GetLastError();
243 } else dwStatus = GetLastError();
244
245 if (hService != NULL) CloseServiceHandle(hService);
246 return dwStatus;
247} // DriverStop

References hSCMan, and OKAY.

Referenced by main().

+ Here is the caller graph for this function:

◆ LoadDriverCleanup()

void LoadDriverCleanup ( void  )
190 {
191 if (hSCMan != NULL) CloseServiceHandle(hSCMan);
192}

References hSCMan.

Referenced by main().

+ Here is the caller graph for this function:

◆ LoadDriverInit()

DWORD LoadDriverInit ( void  )
181 {
182 // connect to local service control manager
183 if ((hSCMan = OpenSCManager(NULL, NULL,
184 SC_MANAGER_ALL_ACCESS)) == NULL) {
185 return -1;
186 }
187 return OKAY;
188}

References hSCMan, and OKAY.

Referenced by main().

+ Here is the caller graph for this function: