Sign in to follow this  

[Win32] Launching a driver as service

Recommended Posts

Hello everyone

I hope my posting will be moderate even though the fact that i am slowly getting furious because my operating system seems to do random stuff :D.

For testing purposes i have developed a very small driver which in now would like to test. I found a nice code which loads the driver as a service. But when i start the service i get the error, that the driver was not found (error code 2). My code looks like that:

#include <windows.h>
#include <iostream>

int main()


if(hMgr == NULL)
std::cout << "Unable to open the SC manager!" << std::endl;
return 0;

SC_HANDLE hService = CreateService(hMgr, "ExampleTestDriver", "Example Test Driver", SERVICE_START | DELETE | SERVICE_STOP, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_IGNORE, "System32\\Drivers\\ExampleTestDrive.sys", NULL, NULL, NULL, NULL, NULL);

hService = OpenService(hMgr, "ExampleTestDrive", SERVICE_START | DELETE | SERVICE_STOP);

if(hService == NULL)
std::cout << "Unable to open or create the service!" << std::endl;
return 0;

if(FALSE == StartService(hService, 0, NULL))
std::cout << "Unable to start the service: " << GetLastError() << std::endl;
return 0;

std::cout << "Service started! Press any key to terminate it!" << std::endl;

ControlService(hService, SERVICE_CONTROL_STOP, &ss);




return 0;

I have Windows 7 64 Bit and the driver is compiled as x64 binary. As soon as i run my service launcher (as administrator) i get the error that it was unable to start the service with error code 2. After doing some random stuff (deleting registry keys, removing the driver and recopy it, rename the service name, ...) suddenly another error popped up: 577 - driver is not signed. So i test signed the driver using SignTool and turned on the test mode using bcdedit and tried to start the service again -> error code 2 '-.-.

What am i doing wrong? I just want to test my driver which is actually completed since approximately 7 hours but cannot be installed to be tested....

Thanks for any help before im getting crazy :P

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this