# [Win32] Launching a driver as service

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

## 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 .

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