reactos/modules/rosapps/applications/sysutils/utils/driver/unload/unload.c
Serge Gautherie 2b93352907
[LOAD][UNLOAD] Fix w*printf() format strings (#3319)
Also:
- Set ServiceName.MaximumLength.
- Fix MSVC warnings:
'...\load\load.c(19): warning C4267: '=': conversion from 'size_t' to 'USHORT', possible loss of data
'...\unload\unload.c(19): warning C4267: '=': conversion from 'size_t' to 'USHORT', possible loss of data'
'...\unload\unload.c(24): warning C4476: 'wprintf' : unknown type field character 'U' in format specifier'
'...\unload\unload.c(24): warning C4474: 'wprintf' : too many arguments passed for format string'
2021-02-08 16:47:13 +01:00

37 lines
861 B
C

/*
* Unload a device driver
*/
#define WIN32_NO_STATUS
#include <windows.h>
#include <stdlib.h>
#include <ntndk.h>
int wmain(int argc, WCHAR * argv[])
{
NTSTATUS Status;
UNICODE_STRING ServiceName;
if (argc != 2)
{
wprintf(L"Usage: unload <ServiceName>\n");
return 0;
}
ServiceName.Length = (USHORT)((52 + wcslen(argv[1])) * sizeof(WCHAR));
ServiceName.MaximumLength = ServiceName.Length + sizeof(UNICODE_NULL);
ServiceName.Buffer = malloc(ServiceName.MaximumLength);
wsprintf(ServiceName.Buffer,
L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\%s",
argv[1]);
wprintf(L"Unloading %wZ\n", &ServiceName);
Status = NtUnloadDriver(&ServiceName);
free(ServiceName.Buffer);
if (!NT_SUCCESS(Status))
{
wprintf(L"Failed: 0x%08lx\n", Status);
return 1;
}
return 0;
}