Hi All,
I am writing WDM based legacy driver, it is not a hardware driver. I am starting the driver as a Windows service.
For some reason, I want to prevent driver unload using sc/net stop. I tried few methods like leaking device object handle, creating one more dummy device object. But nothing prevents the driver unload execution callback from the system.
Using the below approach, I am able to stop the driver unload.
-
Setting unload function to NULL.
DriverObject->DriverUnload = NULL; -
Another approach:
DriverObject->DriverExtension->AddDevice = TestAddDevice;
NTSTATUS TestAddDevice(
PDRIVER_OBJECT DriverObject,
PDEVICE_OBJECT PhysicalDeviceObject)
{
return STATUS_NO_SUCH_DEVICE;
}
But the above methods prevent the unload till the system reboot.
Actually, I want to customize the driver unload callback, kind of switching on/off the unload, based on some action from the upper layer.
Is there anyway to dynamically enable/disable driver unload.
Thanks,