흠.. 시간 잘 간다..
그나저나.. 블루스크린은 언제쯤 그만 보려나..
1 #include <windows.h>
2 #include <winsvc.h>
3 #include <stdio.h>
4
5 #include "driver.h"
6
7 int InstallDriver(TCHAR *pDeviceName)
8 {
9 SC_HANDLE hManager, hService;
10 TCHAR driverPath[MAX_PATH], buffer[MAX_PATH];
11
12 GetCurrentDirectory(MAX_PATH, driverPath);
13 _stprintf_s(buffer, sizeof(buffer), _T("\\%s.sys"), pDeviceName);
14 _tcscat_s(driverPath, sizeof(driverPath), buffer);
15
16 // 서비스 컨트롤러 접속
17 if ((hManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) == NULL)
18 return -1;
19
20 // 드라이버를 서비스에 등록
21 hService = CreateService(
22 hManager,
23 pDeviceName,
24 pDeviceName,
25 SERVICE_ALL_ACCESS,
26 SERVICE_KERNEL_DRIVER,
27 SERVICE_DEMAND_START,
28 SERVICE_ERROR_NORMAL,
29 driverPath,
30 NULL, NULL, NULL, NULL, NULL
31 );
32
33 // 기존에 등록된게 있다면 재활용
34 if (hService == NULL) {
35 if ((hService = OpenService(hManager, pDeviceName, SERVICE_ALL_ACCESS)) == NULL) {
36 CloseServiceHandle(hManager);
37 return -1;
38 }
39 }
40
41 // 서비스 시작 ㄱㄱ
42 StartService(hService, 0, NULL);
43 CloseServiceHandle(hService);
44 CloseServiceHandle(hManager);
45
46 return 0;
47 }
48
49 int UninstallDriver(TCHAR *pDeviceName)
50 {
51 SC_HANDLE hManager, hService;
52 SERVICE_STATUS servStatus;
53
54 if ((hManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS)) == NULL)
55 return -1;
56
57 if ((hService = OpenService(hManager, pDeviceName, SERVICE_ALL_ACCESS)) != NULL) {
58 ControlService(hService, SERVICE_CONTROL_STOP, &servStatus );
59 DeleteService(hService);
60 CloseServiceHandle(hService);
61 }
62
63 CloseServiceHandle(hManager);
64
65 return 0;
66 }
뭐.. 요건.. 드라이버 로딩부..