简体   繁体   English

相当于在Windows XP或更高版本中以编程方式从文件夹安装驱动程序

[英]Do the equivalent of installing a driver from a folder, programatically, in Windows XP or higher

I need to have a driver installed in my customers' computers. 我需要在客户的计算机上安装驱动程序。 Unfortunately, the only way to do this right now is having Windows show its "Hardware Update Wizard" when the device is plugged in, and then have the user do the following: 不幸的是,现在唯一的方法是让Windows在插入设备时显示其“硬件更新向导”,然后让用户执行以下操作:

  • select "No, not this time", 选择“不,不是这次”,
  • select "Install from a specific location (Advanced)", 选择“从特定位置安装(高级)”,
  • check or uncheck appropriate checkboxes and select the folder that contains the drivers 选中或取消选中相应的复选框,然后选择包含驱动程序的文件夹

All of which is slow and unfriendly for a non technically savvy user. 对于技术娴熟的用户来说,所有这些都是缓慢且不友好的。 For the people who must install the device in many computers, it's a repetitive and annoying process too. 对于必须在许多计算机上安装设备的人来说,这也是一个重复且烦人的过程。

So, I'm trying to write a very simple program that will prompt the user to plug in the device. 所以,我正在尝试编写一个非常简单的程序,它将提示用户插入设备。 Then the program will do the same steps above automatically. 然后程序将自动执行上述相同的步骤。 My questions: 我的问题:

  • I wonder if there is a Windows API that looks for drivers in a folder, since that's what the Wizard does. 我想知道是否有一个Windows API在文件夹中查找驱动程序,因为这就是向导所做的。
  • I've just discovered the function DriverPackageInstall . 我刚刚发现了函数DriverPackageInstall Would passing the .inf file as a parameter do what I want? 将.inf文件作为参数传递给我想要的是什么? (I'll be writing code to test this in the meanwhile, just give me some time to download the Windows Driver Kit and set up a project...). (我将编写代码来同时测试它,只需给我一些时间下载Windows驱动程序工具包并设置项目......)。
  • Any other suggestions? 还有其他建议吗?

You did not specify which version of Windows. 您没有指定哪个版本的Windows。

On Windows 7 there`s pnputil: 在Windows 7上有pnputil:

c:\>pnputil -?
Microsoft PnP Utility
Usage:
------
pnputil.exe [-f | -i] [ -? | -a | -d | -e ] <INF name>
Examples:
pnputil.exe -a a:\usbcam\USBCAM.INF      -> Add package specified by USBCAM.INF
pnputil.exe -a c:\drivers\*.inf          -> Add all packages in c:\drivers\
pnputil.exe -i -a a:\usbcam\USBCAM.INF   -> Add and install driver package
pnputil.exe -e                           -> Enumerate all 3rd party packages
pnputil.exe -d oem0.inf                  -> Delete package oem0.inf
pnputil.exe -f -d oem0.inf               -> Force delete package oem0.inf
pnputil.exe -?                           -> This usage screen

programmatically, you can use DiInstallDriver 以编程方式,您可以使用DiInstallDriver

There are several ways and some depend on the type of device you have. 有几种方法,有些方法取决于您拥有的设备类型。

There are several tools for installing driver packages. 有几种工具可用于安装驱动程序包。

  1. DpInst is a complete application which can show a wizard and be customized to install a driver package DpInst是一个完整的应用程序,可以显示向导并进行自定义以安装驱动程序包

  2. DifXApp builds a msi package which can be used to install drivers DifXApp构建一个msi包,可用于安装驱动程序

  3. DifxApi is the API which DpInst and DifxApp use to install drivers. DifxApi是DpInst和DifxApp用于安装驱动程序的API。

  4. Directly using the SetupApi functions. 直接使用SetupApi功能。

    Here the functions SetupCopyOEMInf and UpdateDriverForPlugAndPlayDevices provide the corresponding entry points for a driver setup. 这里的函数SetupCopyOEMInfUpdateDriverForPlugAndPlayDevices为驱动程序设置提供了相应的入口点。 These are contained in the WinSDK. 这些包含在WinSDK中。

DpInst/DifxApp/DifxApi are part of the Windows Driver Kit (WDK). DpInst / DifxApp / DifxApi是Windows驱动程序工具包(WDK)的一部分。

DifX (found in the Windows DDK) is the Microsoft recommended way for installing drivers. DifX(在Windows DDK中找到)是Microsoft推荐的安装驱动程序的方法。 DPInst is the standalone tool and DifX API is the programmatic way. DPInst是独立工具,DifX API是编程方式。

If the driver is signed, you can use DPInst (or DifX API) to preinstall it and then it'll be installed (without any wizards or prompts) as soon as the user inserts the hardware. 如果驱动程序已签名,则可以使用DPInst(或DifX API)进行预安装,然后在用户插入硬件后立即安装(无任何向导或提示)。

If the driver is unsigned (ie has no signed .cat file), then: 如果驱动程序是未签名的(即没有签名的.cat文件),则:

  • on Windows Vista and higher, you can sign it yourself (typically with a certificate you purchase from a CA, though self-signing might be possible) 在Windows Vista及更高版本上,您可以自己签名(通常使用从CA购买的证书,但可能会进行自签名)
  • on Windows XP, you're doomed (unless you apply some real ugly hacks) 在Windows XP上,你注定失败了(除非你应用一些真正丑陋的黑客)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM