彻底删除Windows XP中的驱动程序文件
我正在开发一个应用程序,其中涉及安装一些项目特定的硬件设备。在安装应用程序时,我使用 diffxAPI 将驱动程序 inf 文件推送到 Driverstore 中。但是使用 diffx 卸载后,Windows 注册表中 HKLM\SYSTEM\CurrentControlSet\Enum\USB 下仍然保留了一些引用。当设备被枚举并在设备管理器的 COM 端口部分显示其条目时,这些引用的存在往往会成为一个问题。这就是我用于卸载驱动程序的方法:
DriverPackageUninstall(infName, DRIVER_PACKAGE_DELETE_FILES, ptrInstallerInfo, out fNeedReboot);
我再次想到以编程方式清除这些注册表项,因为我知道我应该设置访问特定密钥的访问权限。这就是我所做的:
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);
但是这段代码抛出异常,因为它不允许我以编程方式设置访问控制。在 Windows XP 计算机中,我可以通过注册表编辑器手动设置此权限。 XP中有没有一种有效的方法可以完全删除驱动程序文件?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
很奇怪。 DifxAPI 应删除 a) 驱动程序存储中的驱动程序包,b) 该驱动程序的已安装实例。您确定那些旧设备实例(在 HKLM\SYSTEM\CurrentControlSet\Enum\USB 中)正在使用您要删除的驱动程序,或者可能是其 .INF 文件的旧版本或其他什么?
但基本上,Microsoft 不希望您使用 Enum 和更改 ACL。他们宁愿让您通过SetupAPI 枚举和删除设备(如Windows DDK 中的
devcon
示例所示)。我最近编写了代码来做到这一点:我的所有设备共享相同的自定义设备类,因此它们很容易枚举,然后我按照
devcon
中的代码盲目地删除了它们。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
.