问题描述
嗨专家,
安装我的Windows Forms应用程序会对USB子系统造成严重破坏。插入机器的任何USB设备都将无法正常工作,除非在我的软件安装之前已经插入USB端口。
有没有人有过之前的这种行为?甚至可以解决如何不打扰其他供应商设备的问题?
更详细的描述
应用程序的目的是与我公司销售的设备进行通信。通过 []。为了确保应用程序能够与我们的某个设备进行通信而不是使用这些芯片的任何设备,我们已经为其分配了一个单独的PID。改编的ftdibus.inf文件反映了这种变化。
USB驱动程序文件保存在安装路径的子目录中(用户可以选择)。为了让Windows了解这些文件,我的安装程序会更改注册表项 HKLM \Software \ Microoft \ Windows \ CurrentVersion \DevicePath
。正确的USB驱动程序文件路径将附加到该键的值。这留下了任何可能未被触及的东西。卸载会删除我们的更改。由于我的应用程序检测到我们的设备,这似乎按预期工作(没有注册表更改,但它没有)。
驱动程序由于改变.inf文件。缺乏认证意味着无法以静默方式安装驱动程序。为了保存用户很多恼人的消息框点击,每次插入我们的另一个设备时都不会重新安装驱动程序。所以在 HKLM \SYSTEM \也有一个注册表项CurrentControlSet \Control \UsbFlags \ IgnoreHWSerNum1234CDEF
除此之外,我没有对任何注册表更改进行编码。
效果
有问题的PC已知的USB设备,并连接到他们拥有的USB端口已经连接,继续工作。
将已知设备插入USB端口,之前没有连接到设备管理器中的未知设备设备不工作。
将一个全新的设备连接到PC会导致安装它的驱动程序(至少从任务栏弹出一个弹出窗口),还有在设备管理器中显示未知设备。
卸载软件不会恢复正常的USB行为。
我目睹拒绝工作的所有设备都可以通过在设备管理器中明确安装驱动程序来激活。
问题出现在Windows XP教授和Windows 7 64教授
我从软件安装之前和之后获得两个regedit.exe导出。已提到的DevicePath注册表项让我感到困惑:
Hi experts,
the installation of my Windows Forms application wreaks havoc on the USB subsystem. Any USB device plugged in the machine won't function unless it has already been plugged into that very USB port at a time before my software was installed.
Has anyone had such behaviour before? And maybe even a solution how to not disturb other vendors' devices?
More detailed description
The application's purpose is to communicate with a device my company sells. Communication is done via a dedicated USB IC from http://www.ftdichip.com/[^]. For the application to be sure to communicate to one of our devices instead of anything that also uses those chips, we have been assigned a separate PID. An adapted ftdibus.inf file reflects this change.
The USB driver files are held in a subdirectory of the installation path (which the user can choose). To make Windows aware of these files, my installer alters the registry key HKLM\Software\Microsoft\Windows\CurrentVersion\DevicePath
. The correct USB driver files path is appended to that key's value. This leaves anything that may have been there untouched. Uninstallation removerts our changes. Since our devices are detected by my application, this seems to work as expected (without the registry change, it does not).
The driver loses its certification due to the changed .inf file. Lack of certification means not to be able to silently install the driver. To save the user a lot of annoying message box clicking, the driver shall not be re-installed every time another one of our devices is plugged in. So there's also a registry entry at HKLM\SYSTEM\CurrentControlSet\Control\UsbFlags\IgnoreHWSerNum1234CDEF
Other than that, I didn't code any registry changes.
Effects
USB devices that are already known to the PC in question, and are connected to a USB port that they have already been connected to, keep working.
Plugging a known device into a USB port it has not earlier been connected to result in an "Unknown Device" in Device Manager and the device not working.
Connecting a totally new device to the PC causes its driver to be installed (at least a pop-up from the taskbar tells so) and also shows an "Unknown Device" in Device Manager.
Un-installing the software doesn't restore normal USB behaviour.
All devices that I witnessed refusing to work could be activated by explicitly installing their drivers from within Device Manager.
The problem was observed on Windows XP Prof and Windows 7 64 Prof.
I got two regedit.exe exports from before and after the software installation. The already mentioned DevicePath registry key baffles me:
before:
"DevicePath"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,\
00,74,00,25,00,5c,00,69,00,6e,00,66,00,00,00
after:
"DevicePath"="%SystemRoot%\\inf;C:\\Program Files (x86)\\Corporation\\Application Name\\include\\USBDriver"
使用带有漂亮的树视图的regedit.exe并编辑我从未见过这种格式的字段。刚才在WinMerge。
[/ Edit]
Using regedit.exe with the nice tree view and edit fields I've never seen this format. Just now in WinMerge.
[/Edit]
推荐答案
[DllImport("advapi32.dll", SetLastError = true)]
static extern uint RegSetValueEx(
int hKey,
[MarshalAs(UnmanagedType.LPStr)]
String lpValueName,
int lpReserved,
Microsoft.Win32.RegistryValueKind dwType,
IntPtr lpData,
int cbData
);
并将 dwType
设置为 String
。但新安装的笔记本电脑注册表显示 ExpandString
是正确的。 ExpandString 类型会导致%SystemRoot%
扩展到实际路径,这是因意外更改而阻止的。
我添加的路径不包含任何此类变量,因此就像魅力一样,并通过了我们所有的测试。原来的条目必须扩展到工作,所以我打破了它。
非常感谢你的所有建议。这包括我拒绝的那些。
And set dwType
, to String
. But a freshly installed notebook's registry shows that ExpandString
would have been correct. The ExpandString type causes %SystemRoot%
to be expanded to the actual path, which is prevented by my accidental change.
The path I added doesn't contain any such variables, therefore works like a charm and passes all our tests. The original entry has to be expanded to work and so I broke it.
Thanks a lot for all your suggestions. That includes the ones I rejected.
这篇关于USB驱动程序安装会破坏其他驱动程序的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!