I am trying to install a driver with windows C++. Registering and starting the service is working fine but I have troubles with installing the INF file. I've look over the internet and wrote some code but can't make it work. Make it short, I just need help with installing the INF file programmly.
Make it short, it doesn't install the INF file. I also checked GetLastError() after I call SetupOpenInfFile and it returns 0. Btw, is there any way to get rid of the INF file?
SC_HANDLE hSCManager;
SC_HANDLE hService;
SERVICE_STATUS ss;
SERVICE_STATUS_PROCESS status;
HINF HInf;
UINT ErrorLine;
PCWSTR szInfFileName = L"C://scanner.inf";
PVOID Context = NULL;
PBOOL FileWasInUse = NULL;
LPCSTR SourceFile = "scanner.sys";
LPCSTR SourcePathRoot = "C://test/";
LPCSTR DestinationName ="C://scanner.sys";
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
printf("Load Driver\n");
if (hSCManager)
{
HInf = SetupOpenInfFile(szInfFileName, NULL, INF_STYLE_WIN4, &ErrorLine);
printf("Create Service\n");
hService = CreateService(hSCManager, L"scanner", L"scanner Driver", SERVICE_START | DELETE | SERVICE_STOP, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_IGNORE, L"C://scanner.sys", NULL, NULL, NULL, NULL, NULL);
if (!hService)
{
hService = OpenService(hSCManager, L"scanner", SERVICE_START | DELETE | SERVICE_STOP);
}
if (hService)
{
printf("Start Service\n");
StartService(hService, 0, NULL);
printf("Press Enter to close service\r\n");
getchar();
ControlService(hService, SERVICE_CONTROL_STOP, (LPSERVICE_STATUS)&status);
CloseServiceHandle(hService);
DeleteService(hService);
}
CloseServiceHandle(hSCManager);
}