执行相当于在 Windows XP 或更高版本中以编程方式从文件夹安装驱动程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5265377/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Do the equivalent of installing a driver from a folder, programatically, in Windows XP or higher
提问by Jong Bor Lee
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.
- I've just discovered the function
DriverPackageInstall
. Would passing the .inf file as a parameter do what I want? (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...). - Any other suggestions?
- 我想知道是否有一个 Windows API 可以在文件夹中查找驱动程序,因为向导就是这样做的。
- 我刚刚发现了这个功能
DriverPackageInstall
。将 .inf 文件作为参数传递会做我想要的吗?(我将同时编写代码来测试这个,请给我一些时间下载 Windows 驱动程序工具包并设置一个项目......)。 - 还有其他建议吗?
回答by John
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
回答by Christopher
There are several ways and some depend on the type of device you have.
有多种方法,有些方法取决于您拥有的设备类型。
There are several tools for installing driver packages.
有多种工具可用于安装驱动程序包。
DpInstis a complete application which can show a wizard and be customized to install a driver package
DifXAppbuilds a msi package which can be used to install drivers
DifxApiis the API which DpInst and DifxApp use to install drivers.
Directly using the SetupApi functions.
Here the functions SetupCopyOEMInfand UpdateDriverForPlugAndPlayDevicesprovide the corresponding entry points for a driver setup. These are contained in the WinSDK.
DpInst是一个完整的应用程序,它可以显示一个向导并进行自定义以安装驱动程序包
DifXApp构建了一个可用于安装驱动程序的 msi 包
DifxApi是 DpInst 和 DifxApp 用于安装驱动程序的 API。
直接使用 SetupApi 函数。
这里的SetupCopyOEMInf和UpdateDriverForPlugAndPlayDevices函数为驱动程序设置提供了相应的入口点。这些都包含在 WinSDK 中。
DpInst/DifxApp/DifxApi are part of the Windows Driver Kit (WDK).
DpInst/DifxApp/DifxApi 是 Windows 驱动程序工具包 (WDK) 的一部分。
回答by Ilya
DifX (found in the Windows DDK) is the Microsoft recommended way for installing drivers. DPInst is the standalone tool and DifX API is the programmatic way.
DifX(在 Windows DDK 中找到)是 Microsoft 推荐的安装驱动程序的方式。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 (i.e. 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)
- on Windows XP, you're doomed (unless you apply some real ugly hacks)
- 在 Windows Vista 和更高版本上,您可以自己签名(通常使用您从 CA 购买的证书,但也可以进行自签名)
- 在 Windows XP 上,你注定要失败(除非你应用一些真正丑陋的技巧)