C ++安装inf和sys

时间:2017-01-11 18:02:59

标签: c++ windows driver

我正在尝试使用Windows C ++安装驱动程序。 注册和启动服务工作正常但我在安装INF文件时遇到了麻烦。 我查看了互联网并编写了一些代码,但无法使其正常工作。 简而言之,我只需要帮助安装INF文件程序。

简而言之,它不会安装INF文件。我在调用SetupOpenInfFile后检查了GetLastError(),它返回0。 顺便问一下,有没有办法摆脱INF文件?

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

0 个答案:

没有答案