首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用CreateService的umdf2驱动程序

使用CreateService的umdf2驱动程序
EN

Stack Overflow用户
提问于 2019-01-10 10:26:08
回答 1查看 208关注 0票数 0

是否可以在Windows10中使用CreateServiceStartService API启动umdf2驱动程序?我正在寻找任何我可以参考的运行样本。

我以前用WDM驱动做过,但目前我用umdf2驱动做不到。以下是代码

代码语言:javascript
复制
WCHAR strPath[MAX_PATH];
GetCurrentDirectory(MAX_PATH, strPath);
std::wstring binaryPath(strPath);
binaryPath += L"\\" + pDeviceName + L".dll";

std::string logPath(binaryPath.begin(), binaryPath.end());
cout << "Load Path : " << logPath << endl;

SC_HANDLE hManager, hService;
hManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
if (!hManager) {
    DWORD err = GetLastError();
    if (err == ERROR_ACCESS_DENIED) {
        cout << "OPenSCManager Access denied - run administration access" << endl;
    } else {
        cout << "OPenSCManager Error : " << err << endl;
    }
    return;
}

hService = CreateService(hManager, pDeviceName.c_str(), pDeviceName.c_str(), SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START,
    SERVICE_ERROR_NORMAL, binaryPath.c_str(), NULL, NULL, NULL, NULL, NULL);
if (!hService) {
    hService = OpenService(hManager, pDeviceName.c_str(), SERVICE_ALL_ACCESS);
    if (!hService) {
        CloseServiceHandle(hManager);
        return;
    }
}

if (!StartService(hService, 0, NULL)) {
    DWORD err = GetLastError();
    cout << "StartService Error : " << err << endl;
    if (err == ERROR_SERVICE_ALREADY_RUNNING) {
        cout << "Already running" << endl;
    }
}

CloseServiceHandle(hManager);
CloseServiceHandle(hService);

pDeviceName指的是驱动程序名称。代码执行失败,错误为2:

代码语言:javascript
复制
StartService Error : 2

我在Win7和Win10中进行了测试,结果是一样的。

EN

回答 1

Stack Overflow用户

发布于 2019-01-10 14:20:26

错误代码告诉了我们很多事情:

系统找不到指定的文件。

首先,检查(pDeviceName).dll是否位于当前目录中。

其次,使用Dependency Walker等工具检查其依赖关系,将其移动到当前目录或系统目录,以确保系统也可以找到这些依赖关系。

然后尝试检查"regedit",打开密钥HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\pDeviceName,或其他类似的名称。检查密钥值"ImagePath",路径是您第一次创建它。将dll移动到路径或将路径更改为dll。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54121151

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档