Why am I getting error code 6 on StartService?

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) { // If initial startup of the driver failed, it will fail here. process_error(); return 0; } } if(hService) { printf("Start Service\n"); if(StartService(hService, 0, NULL) == 0) { // Start service ALWAYS returns 0. Only when executed for the first time. Next time it fails on OpenService. process_error(); printf("Did not start!\n"); } printf("Press Enter to close service\r\n"); getchar(); ControlService(hService, SERVICE_CONTROL_STOP, &ss); DeleteService(hService); CloseServiceHandle(hService); } CloseServiceHandle(hSCManager); } return 0; } 

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.

+5
source share
5 answers

I tracked this to the driver project settings. There were no KMDF versions in the project.

Adjust the following (in the "Driver Model Settings" section):
- Version KMDF Major = 1
- Version KMDF Minor = 9

Click OK, recompile and reinstall. Worked for me!

+8
source

A few thoughts:

You are using HANDLE hSCManager && HANDLE hService, they must be declared as SC_HANDLE

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682450(v=vs.85).aspx

" lpBinaryPathName [in, optional] Full path to the service binary. If the path contains a space, it must be specified so that it is correctly interpreted. For example," d: \ my share \ myservice.exe "should be specified as" \ " d: \ my share \ myservice.exe \ "".

Try using the full path to the driver

0
source

I had the same problem starting my kernel driver:


startervice failed 6:

descriptor invalid

It turned out that the "GUID class GUID" was the same as another one (detected through the device manager, event view showed different driver names).

The online generator is used to create a new GUID and is replaced by the one in the project .inf file (in VS, and not in a text editor or in some). After recovery and deployment on the target machine, everything worked fine.

Hope this helps ...

0
source

Run Visual Studio with administrator privileges.

0
source

Your call to OpenSCManager() only requests SC_MANAGER_CREATE_SERVICE permission, which is not enough for OpenService() or StartService() to succeed.

-1
source

Source: https://habr.com/ru/post/1444397/


All Articles