以编程方式为特定设备安装特定驱动程序(以及当预安装失败时)
我有一个签名的驱动程序,我需要使用 C#(针对 Vista 和 7 64 位)以编程方式为特定 USB 设备安装它。
我发现使用 DriverPackagePreinstall 函数 (这里是如何P/Invoke它):通过在设备插入USB之前调用它,一旦检测到这种情况,Windows就能够将驱动程序与设备关联起来。
当设备在未预安装驱动程序的情况下插入 USB 时,就会出现问题。可能会发生为该设备安装另一个驱动程序的情况(在一台测试 PC 中,我发现已安装通用驱动程序,并且该设备列在设备管理器的“其他设备”下)。
试图解决这个问题,到目前为止,我已经能够使用 SetupDiGetClassDevs,SetupDiEnumDeviceInfo 和 SetupDiGetDeviceRegistryProperty 函数以便通过 VID 和 PID(供应商和产品标识符)识别设备。现在我有了 SP_DEVINFO_DATA< /a> 对于我的设备我想我必须调用 InstallSelectedDriver 函数,不是是吗?如果是,您能否告诉我如何 P/Invoke 该函数(我在 pinvoke.net 上找不到它)以及如何通过指定我要为我的设备安装的驱动程序来使用它(假设我有 INF 路径) ?
I have a signed driver and I need to install it programmatically for a specific USB device using C# (targeting Vista and 7 64-bit).
I found very easy the use of the DriverPackagePreinstall function within the DIFx API (here is how to P/Invoke it): by calling it before the device is plugged into the USB, Windows is able to associate the driver to the device once this is detected.
The problems arise when the device is plugged into the USB without having pre-installed the driver. It can happen that another driver is installed for that device (in one test PC I found that a generic driver has been installed and that the device is listed under "Other devices" in Device Manager).
Trying to solve this problem, up to now I've been able to detect that the device is there by using the SetupDiGetClassDevs, the SetupDiEnumDeviceInfo and the SetupDiGetDeviceRegistryProperty functions in order to identify the device by its VID and PID (vendor and product identifier). Now that I have the SP_DEVINFO_DATA for my device I guess I've to call the InstallSelectedDriver function, isn't it? If yes, could you please tell me how to P/Invoke that function (I cannot find it on pinvoke.net) and how to use it by specifying the driver I want to install for my device (supposing I've the INF path)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在此处找到了我正在搜索的示例。 InstallSelectedDriver 的 P/Invoke 对我来说是这样的:
I found a sample for exactly what I was searching for here. The P/Invoke for InstallSelectedDriver works for me as: