Merging r37048, r37051, r37052, r37055 from the-real-msvc branch
[reactos.git] / rostests / win32 / kmtloader / kmtloader.c
1 /*
2 * Kernel-Mode Tests Loader (based on PnP Test Driver Loader by Filip Navara)
3 *
4 * Copyright 2004 Filip Navara <xnavara@volny.cz>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; see the file COPYING.LIB.
18 * If not, write to the Free Software Foundation,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22 /* INCLUDES *******************************************************************/
23
24 #include <windows.h>
25 #include <stdio.h>
26
27 /* PUBLIC FUNCTIONS ***********************************************************/
28
29 int main()
30 {
31 SC_HANDLE schSCManager;
32 SC_HANDLE schService;
33 PWCHAR DriverName = L"KMTEST";
34 WCHAR ServiceExe[MAX_PATH];
35
36 printf("Kernel Mode Tests loader\n\n");
37 GetCurrentDirectoryW(MAX_PATH, ServiceExe);
38 wcscat(ServiceExe, L"\\kmtest.sys");
39
40 printf("Opening SC Manager...\n");
41 schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
42
43 if (schSCManager == NULL)
44 {
45 DWORD Err = GetLastError();
46 printf("OpenSCManager failed with error 0x%lx\n", Err);
47 return 0;
48 }
49
50 printf("Creating service...\n");
51 schService = CreateServiceW(
52 schSCManager,
53 DriverName,
54 DriverName,
55 SERVICE_ALL_ACCESS,
56 SERVICE_KERNEL_DRIVER,
57 SERVICE_DEMAND_START,
58 SERVICE_ERROR_NORMAL,
59 ServiceExe,
60 NULL,
61 NULL,
62 NULL,
63 NULL,
64 NULL);
65
66 if (schService == NULL)
67 {
68 printf("Opening service...\n");
69 schService = OpenServiceW(schSCManager, DriverName, SERVICE_ALL_ACCESS);
70 }
71
72 if (schService == NULL)
73 {
74 DWORD Err = GetLastError();
75 printf("Create/OpenService failed with error 0x%lx\n", Err);
76 CloseServiceHandle(schSCManager);
77 return 0;
78 }
79
80 //for (;;) ;
81
82 printf("Starting service...\n");
83 StartService(schService, 0, NULL);
84
85 printf("Cleaning up and exiting\n");
86 CloseServiceHandle(schService);
87 CloseServiceHandle(schSCManager);
88
89 return 0;
90 }