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?
It turns out that you need to add a
DriverUnloadfunction:However, this is only sufficient if you’re linking with
/DRIVER.If you’re linking with
/DRIVER:WDM(meaning thatIMAGE_DLLCHARACTERISTICS_WDM_DRIVERis set in theDllCharacteristicsfield) 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.