For my purposes, I need to write a kernel mode driver for Windows. I am currently trying to get it working under Windows 7 x64.
I created a simple project in Visual Studio 2012 with the default code for the KMDF driver. I compiled the code with the signature on the test. The driver has been compiled and signed. I also have the signature verification feature enabled, as shown in the lower left corner of my desktop.
When I try to start the driver as a service, I always get error code 6: error processing incorrectly. (Since then, I have simplified the code to just try to run it, but still did not work, by default the code does not work)
Basically, I have the same problem as the question asked here
https://stackoverflow.com/questions/12080157/startservice-error-6
Unfortunately, they never answered him. I tried the provided solution, but that didn't help either.
My code that is trying to start the driver is
int _cdecl main(void) { HANDLE hSCManager; HANDLE hService; SERVICE_STATUS ss; hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE); printf("Load Driver\n"); if(hSCManager) { printf("Create Service\n"); hService = CreateService(hSCManager, "Example", "Example Driver", SERVICE_ALL_ACCESS | SERVICE_START | DELETE | SERVICE_STOP , SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_IGNORE, "\\path\\to\\driver\\KMDFDriver1.sys", NULL, NULL, NULL, NULL, NULL); if(!hService) { hService = OpenService(hSCManager, "Example", SERVICE_ALL_ACCESS | SERVICE_START | DELETE | SERVICE_STOP); if(!hService) {
And this is the driver code
DRIVER_INITIALIZE DriverEntry; #ifdef ALLOC_PRAGMA #pragma alloc_text (INIT, DriverEntry) #endif NTSTATUS DriverEntry( _In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath ) { WDF_DRIVER_CONFIG config; NTSTATUS status; DbgPrint("Hello World!\n"); WDF_DRIVER_CONFIG_INIT(&config, NULL ); config.DriverInitFlags = WdfDriverInitNonPnpDriver; status = WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES, &config, WDF_NO_HANDLE ); if (!NT_SUCCESS(status)) { KdPrint( ("WdfDriverCreate failed with " "status 0x%x\n", status)); } return status; }
The process_error() function is a wrapper around GetLastError() , which, in addition to providing a numerical value, displays a text version of the error code. I have exhausted all the options provided to me to solve this problem. Only one occurrence of this problem was found in a Google search, and a question was asked here.
What is the problem?
Additional notes: the driver was compiled with Visual Studio 2012 Ultimate, and my startup code was compiled using MinGW-W64 (using GCC). But the startup code should not matter like a driver.
Additional notes 2: after a long thought, what could be wrong, I started thinking if this is a test sign certificate, because I tried the driver source code provided from MSDN and after successful compilation I still got ERROR_INVALID_HANDLE (error code 6) with trying to run it. I still haven't found a solution.