Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12231

installing and uninstalling usb device drivers in windows 10/11 programmatically [closed]

$
0
0

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

"Software\Policies\Microsoft\Windows\DeviceInstall\Restrictions\AllowDeviceIDs"

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/reload thedrivers, I tried devcon, UpdateDriverForPlugAndPlayDevices but itdidn't work as I wanted ( I don't want to reboot each time a driveris installed) and the inf files I'm using are from the path%SystemRoot%\inf ( which are not allowed forUpdateDriverForPlugAndPlayDevices function).

  2. I don't know how can I get the inf file from the connected device so I can use it to install/uninstall the device driver

  3. In the uninstall process I tried devcon remove, and that was like Iwanted but the problem is, he remove the driver only when the deviceis plugged in, means if a user plugged out his device suddenly theapplication can't uninstall (unload) the drivers. I don't know muchabout drivers how to load/unload or install/uninstall them, wherethey are stored and how can we get the correspondant driver for theconnected device. I want also to take considerations about the factthat multiple devices can be connected in the machine and it shouldnot 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, even if it's not in c#.


Viewing all articles
Browse latest Browse all 12231

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>