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    ServiceName.Length = (wcslen(argv[1]) + 52) * sizeof(WCHAR);
20    ServiceName.Buffer = (LPWSTR)malloc(ServiceName.Length + sizeof(UNICODE_NULL));
21    wsprintf(ServiceName.Buffer,
22       L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\%S",
23       argv[1]);
24    wprintf(L"%s %d %Ud\n", ServiceName.Buffer, ServiceName.Length, wcslen(ServiceName.Buffer));
25    Status = NtUnloadDriver(&ServiceName);
26    free(ServiceName.Buffer);
27    if (!NT_SUCCESS(Status))
28    {
29       wprintf(L"Failed: %X\n", Status);
30       return 1;
31    }
32    return 0;
33 }
34