是否可以在Windows10中使用CreateService和StartService API启动umdf2驱动程序?我正在寻找任何我可以参考的运行样本。
我以前用WDM驱动做过,但目前我用umdf2驱动做不到。以下是代码
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:
StartService Error : 2我在Win7和Win10中进行了测试,结果是一样的。
发布于 2019-01-10 14:20:26
错误代码告诉了我们很多事情:
系统找不到指定的文件。
首先,检查(pDeviceName).dll是否位于当前目录中。
其次,使用Dependency Walker等工具检查其依赖关系,将其移动到当前目录或系统目录,以确保系统也可以找到这些依赖关系。
然后尝试检查"regedit",打开密钥HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\pDeviceName,或其他类似的名称。检查密钥值"ImagePath",路径是您第一次创建它。将dll移动到路径或将路径更改为dll。
https://stackoverflow.com/questions/54121151
复制相似问题