Jump to content
  • Advertisement
Sign in to follow this  
YanickSalzmann

[Win32] Launching a driver as service

This topic is 2594 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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()
{
SERVICE_STATUS ss;

SC_HANDLE hMgr = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);

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);

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

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

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

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

ControlService(hService, SERVICE_CONTROL_STOP, &ss);

CloseServiceHandle(hService);

DeleteService(hService);

CloseServiceHandle(hMgr);

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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!