Reputation: 823
I'm developing an application which involves installation of some project specific hardware devices. On the installation of the application, I'm using difxAPI to push the driver inf files into the Driverstore. But after the unintallation using the difx, there are still some references left in the windows registry, under HKLM\SYSTEM\CurrentControlSet\Enum\USB. The presence of these references tend to be a problem as the devices gets enumerated and showing its entry in COM ports section of Device Manager. This is what I use for uninstalling the drivers:
DriverPackageUninstall(infName, DRIVER_PACKAGE_DELETE_FILES, ptrInstallerInfo, out fNeedReboot);
Again I thought of clearing those registry entries programatically for that I understand I should be setting the access permission for accessing the particular keys. This is what I did:
RegistryAccessRule regAccess = new RegistryAccessRule("Everyone", RegistryRights.FullControl, AccessControlType.Allow);
RegistrySecurity regSecurity = new RegistrySecurity();
regSecurity.AddAccessRule(regAccess);
Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Enum\USB\", true).SetAccessControl(regSecurity);
But this piece of code is throwing an exception as it is not allowing me to set the access control programatically. In a Windows XP machine manually I'm able to set this permission from registry editor. Is there an efficient way in XP by which I can remove the driver files completely?
Upvotes: 0
Views: 1413
Reputation: 5613
It's strange. DifxAPI should remove both a) the driver package from the driver store, b) the installed instances of this driver. Are you sure those old device instances (in HKLM\SYSTEM\CurrentControlSet\Enum\USB
) are using the driver you're removing, or perhaps an older version of its .INF files or whatnot?
Basically, though, Microsoft doesn't want you playing with Enum and changing ACLs. They'd rather have you enumerate and remove devices through SetupAPI (as shown in the devcon
sample in the Windows DDK).
I've lately wrote code to do just that: all my devices share the same custom device class so they were easy to enumerate, and then I blindly removed them following the code from devcon
.
Upvotes: 1