i’m developing an application for windows 10 and 11 in c# to block USB devices by there IDs (VID&PID) and i’m using GPO ” Allow installation of devices that match any of these device ids” with “Prevent installation of devices not described by other policy settings”. when a device is plugged in, the application checks if the device is allowed (from external DB) and added his id in the registries “SoftwarePoliciesMicrosoftWindowsDeviceInstallRestrictionsAllowDeviceIDs”
When the rule is applied, the devices that was already installed there drivers, won’t be considered…
for the first time an allowed device is plugged in, the drivers will be installed automaticaly after adding it to the registries. and when the device is plugged in again, even if his id is not in the registry, he will be utilisable and didn’t be blocked.
i want my application to block the usb devices each time they are plugged out so when they are plugged in again, they should be verified first then install there drivers.
for this i need to uninstall the drivers when the device is plugged out and install it ( or reload it) when he is plugged in.
my problems are:
1- i couldn’t know how should i properly install or reload the drivers, i tried devcon, UpdateDriverForPlugAndPlayDevices but it didn’t work as i wanted ( i don’t want to reboot each time a driver is installed) and the inf files i’m using are from the path %SystemRoot%inf ( which are not allowed for UpdateDriverForPlugAndPlayDevices function).
2- i don’t know how can i get the inf file from the connected device so i can use it to install or uninstall the device driver
3- in the uninstall process i tried devcon remove, and that was like i wanted but the problem is, he remove the driver only when the device is plugged in, means if a user plugged out his device suddenly the application can’t uninstall ( unload) the drivers.
i don’t know much about drivers how to load/ unload or install/uninstall them, where they are stored and how can we get the correspondant driver for the connected device.
i want also to take considerations about the fact that multiple devices can be connected in the machine and it should not affect each others..
so i tried devcon for both installation and uninstallation.
UpdateDriverForPlugAndPlayDevices for installation,( there was an error about the infpath)
can you please help me finding a solution
Soo min is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.