Allow Driver to Stop in Windows?

痴心易碎 提交于 2019-12-13 18:50:26

问题


Some drivers on Windows, like Null and Beep, can be arbitrarily stopped and re-started through the ControlService(..., SERVICE_CONTROL_STOP, ...) operation. Most other drivers, however, cannot be stopped and restarted while the system is running.

I'm making my own driver. How can I tell Windows that my driver can be stopped?


回答1:


It turns out that you need to add a DriverUnload function:

VOID NTAPI DriverUnload(IN DRIVER_OBJECT *DriverObject) { }

NTSTATUS NTAPI DriverEntry(IN PDRIVER_OBJECT DriverObject,
                           IN PUNICODE_STRING RegistryPath)
{
    DriverObject->DriverUnload = DriverUnload; // <--- add this
    return STATUS_SUCCESS;
}

However, this is only sufficient if you're linking with /DRIVER.
If you're linking with /DRIVER:WDM (meaning that IMAGE_DLLCHARACTERISTICS_WDM_DRIVER is set in the DllCharacteristics field) then it seems like this isn't sufficient. I think you may need to do more things, like handling IRPs as well. So check that too.



来源:https://stackoverflow.com/questions/6240515/allow-driver-to-stop-in-windows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!