1 /*
2  * Unload a device driver
3  */
4 #define WIN32_NO_STATUS
5 #include <windows.h>
6 #include <stdlib.h>
7 #include <ntndk.h>
8 
9 int wmain(int argc, WCHAR * argv[])
10 {
11    NTSTATUS Status;
12    UNICODE_STRING ServiceName;
13 
14    if (argc != 2)
15    {
16       wprintf(L"Usage: unload <ServiceName>\n");
17       return 0;
18    }
19 
20    ServiceName.Length = (USHORT)((52 + wcslen(argv[1])) * sizeof(WCHAR));
21    ServiceName.MaximumLength = ServiceName.Length + sizeof(UNICODE_NULL);
22    ServiceName.Buffer = malloc(ServiceName.MaximumLength);
23    wsprintf(ServiceName.Buffer,
24       L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\%s",
25       argv[1]);
26    wprintf(L"Unloading %wZ\n", &ServiceName);
27 
28    Status = NtUnloadDriver(&ServiceName);
29    free(ServiceName.Buffer);
30    if (!NT_SUCCESS(Status))
31    {
32       wprintf(L"Failed: 0x%08lx\n", Status);
33       return 1;
34    }
35 
36    return 0;
37 }
38