WiX Toolset安装设备驱动失败求助:DIFX无法找到驱动包
问题:WiX安装包添加DIFX驱动安装失败
已为WPF程序创建可正常安装的.wixproj安装包,需添加设备驱动安装功能(该驱动为WPF程序部分功能所需)。将驱动文件放入独立组件并使用DIFX的<difx:Driver>标签后,安装包编译正常,但执行安装时DIFX组件报错失败。移除<difx:Driver>标签后,安装可完成且驱动文件能复制到指定目录,但无法完成驱动安装。
相关代码片段
Drivers.wxs文件内容
<?xml version="1.0" encoding="UTF-8"?> <Wix xmlns=http://schemas.microsoft.com/wix/2006/wi xmlns:difx=http://schemas.microsoft.com/wix/DifxAppExtension> <Fragment> <ComponentGroup Id="Drivers"> <ComponentRef Id="cyusb"/> </ComponentGroup> <DirectoryRef Id="INSTALLFOLDER" FileSource="..\Installer\drivers"> <Directory Id='DriverFolder' Name='Drivers'> <Directory Id='CYUSBFolder' Name='CyUSB'> <Component Id="cyusb" Guid="{6125BDA1-74B9-443C-B130-494C60367EA4}"> <File Id="cyusb.sys" Name="CyUSBsys" Vital="yes" Source=".\drivers\cyusb\cyusb3.sys" KeyPath="yes" /> <File Id="cyusb.cat" Name="CyUSBcat" Vital="yes" Source=".\drivers\cyusb\cy_devices.cat" /> <File Id="cyusb.inf" Name="CyUSBinf" Vital="yes" Source=".\drivers\cyusb\Cy_Devices.inf" /> <difx:Driver Legacy="yes"/> </Component> </Directory> </Directory> </DirectoryRef> </Fragment> </Wix>
Product.wxs中Feature组件组引用
<!--Define components, shortcuts, files etc for installer--> <Feature Id="ProductFeature" Title="AnalytacleClientInstaller" Level="1"> <ComponentGroupRef Id="Drivers"/> <ComponentGroupRef Id="ProductComponents" /> <ComponentGroupRef Id="CompiledComponents"/> <ComponentGroupRef Id="FileTypeComponents"/> </Feature>
.wixProj中Difx库引用
<WixLibrary Include="difxapp_x64.wixlib"> <HintPath>difxapp_x64.wixlib</HintPath> <Name>difxapp_x64.wixlib</Name> </WixLibrary>
安装错误日志片段
DIFXAPP: ENTER: InstallDriverPackages() DIFXAPP: INFO: 'CustomActionData' property 'DIFxApp Version' is '2.1'. DIFXAPP: INFO: 'CustomActionData' property 'UI Level' is '2'. DIFXAPP: INFO: 'CustomActionData' property 'componentId' is '{6125BDA1-74B9-443C-B130-494C60367EA4}'. DIFXAPP: INFO: 'CustomActionData' property 'componentPath' is 'C:\Program Files (x86)\MyProj\Drivers\CyUSB\'. DIFXAPP: INFO: 'CustomActionData' property 'flags' is 0x8. DIFXAPP: INFO: 'CustomActionData' property 'installState' is '2'. DIFXAPP: INFO: 'CustomActionData' property 'ProductName' is 'MyProj'. DIFXAPP: INFO: 'CustomActionData' property 'ManufacturerName' is 'manufacturer'. DIFXAPP: INFO: user SID of user performing the install is 'S-1-5-21-1332366759-4080576608-3295227165-1001'. DIFXAPP: INFO: opening HKEY_USERS\S-1-5-21-1332366759-4080576608-3295227165-1001\Software\Microsoft\Windows\CurrentVersion\DIFxApp\Components\{6125BDA1-74B9-443C-B130-494C60367EA4} (User's SID: 'S-1-5-21-1332366759-4080576608-3295227165-1001') ... DIFXAPP: ERROR: no driver packages found in C:\Program Files (x86)\MyProj\Drivers\CyUSB\ DIFXAPP: ERROR: InstallDriverPackages failed with error 0x2 DIFXAPP: RETURN: InstallDriverPackages() 2 (0x2) CustomAction MsiInstallDrivers returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
解决方案
1. 修正驱动文件的Name属性错误
你在<File>标签中设置的Name属性与实际文件名不匹配,导致DIFX无法识别驱动包:
cyusb.sys的Name应为cyusb3.sys(与Source路径中的文件名一致)cyusb.cat的Name应为cy_devices.catcyusb.inf的Name应为Cy_Devices.inf
修正后的<Component>代码:
<Component Id="cyusb" Guid="{6125BDA1-74B9-443C-B130-494C60367EA4}"> <File Id="cyusb.sys" Name="cyusb3.sys" Vital="yes" Source=".\drivers\cyusb\cyusb3.sys" KeyPath="yes" /> <File Id="cyusb.cat" Name="cy_devices.cat" Vital="yes" Source=".\drivers\cyusb\cy_devices.cat" /> <File Id="cyusb.inf" Name="Cy_Devices.inf" Vital="yes" Source=".\drivers\cyusb\Cy_Devices.inf" /> <difx:Driver Legacy="yes"/> </Component>
2. 确保驱动包完整性与数字签名
- 检查驱动包是否完整:除inf、sys、cat文件外,确认是否包含驱动所需的其他文件(如dll、配置文件等)
- 验证cat文件的数字签名:未签名的驱动在Windows 10及以上系统会安装失败,可使用命令
signtool.exe verify /v /pa cy_devices.cat验证签名有效性
3. 匹配安装包架构与DIFX库
你当前引用的是difxapp_x64.wixlib,如果安装包是32位(x86)架构,需替换为difxapp_x86.wixlib,确保库架构与安装包目标架构一致。
4. 替代方案:使用devcon.exe安装驱动
若DIFX方式仍有问题,可改用以下步骤:
- 将对应架构的
devcon.exe加入安装包组件 - 添加自定义Action,在安装完成后执行命令
devcon.exe install Cy_Devices.inf <硬件ID>(替换为你的设备硬件ID) - 确保自定义Action以管理员权限执行,设置
Impersonate="no"
内容的提问来源于stack exchange,提问作者Mersk3
相关产品推荐
相关产品推荐

