Hi,
I am trying to design a process that can install and uninstall a filter
driver on a specific device without restarting the system.
So far what I came up with is this:
Installing a filter driver without restarting the system:
- Disable the device I would like to filter.
- Call CreateService() in order to register the driver.
- Define the driver as a filter for the device by writing to the
UpperFilters registry key. - Enable the device.
Uninstalling a filter driver without restarting the system:
- Disable the device I’m filtering
- Remove the driver from the UpperFilters registry key of the device.
- Call DeleteService() in order to un-register the driver.
- Enable the device.
This seems to be a rather straight forward implementation, but surprisingly
when testing it I got some unexpected behavior from the PnP manager:
When Installing the driver and right after that uninstalling the driver I
noticed that after the DeleteService() the device I was filtering no longer
appeared in the device manager.
I tried to change the order of operations in the hope to get past this weird
behavior, and defined these steps:
Installing a filter driver without restarting the system:
- Call CreateService() in order to register the driver.
- Disable the device I would like to filter.
- Define the driver as a filter for the device by writing to the
UpperFilters registry key. - Enable the device.
Uninstalling a filter driver without restarting the system:
- Disable the device I’m filtering
- Remove the driver from the UpperFilters registry key of the device.
- Enable the device.
- Call DeleteService() in order to un-register the driver.
Now when installing and uninstalling right after that the device still
appeared in the device manager but when trying to disable it in the device
manager I got a message box that said I must restart the system in order to
disable the device.
In an attempt to understand the source of this behavior I did one more test
and restarted the system between the install and uninstall.
When installing, restarting, and uninstalling everything seemed fine in the
device manager but DeleteService() only marked my driver for deletion and
didn’t really remove it.
Can some one explain the three behaviors?
- A disabled device that was previously filtered disappears from the
device manager when the filter driver is deleted. - An enabled device that was previously filtered cannot be disabled
after the filter driver is deleted. - A filter driver that unloaded is only marked for deletion and not
actually deleted even though no one holds a handle to it.
Thank You,
Shahar