如何从 C# 循环 USB 设备? [英] How can I cycle a USB device from C#?
问题描述
我想在某个事件触发后循环(模拟拔出并重新插入)USB 设备(调制解调器).我在 codeproject 上找到了一个示例:
I'd like to cycle (simulate unplug and re-inserting) a USB device (modem) after a certain event has fired. I found a sample on codeproject:
http://www.codeproject.com/KB/system/usbeject.aspx
这使我能够通过其非易失性序列识别并弹出设备,但我需要它进行回收,而不仅仅是弹出.
That allows me to identify+eject the device via its non-volatile serial, but I need it to recycle, not just eject.
我读过这个:
我不明白.
这已在其他 USB 相关帖子中提及:
This has been mentioned in other USB related posts:
http://www.codeproject.com/KB/system/DriveDetector.aspx
这与我的问题无关.
推荐答案
使用名为 devcon 的命令行工具使其工作,然后我从代码中调用它.
Got it working by using a commandline tool called devcon, which I then called from code.
将 devcon.exe 放入系统路径之一,以便在任何地方都可以使用.
Dropped devcon.exe into one of the system paths so it works everywhere.
开发者大会:开发者大会
调用:DEVCON Remove *usb"*MI_01"
called: DEVCON Remove *usb"*MI_01"
然后调用:DEVCON rescan
then called: DEVCON rescan
代码:
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "DEVCON";
proc.StartInfo.Arguments = "Remove *usb"*MI_01";
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.Start();
这篇关于如何从 C# 循环 USB 设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!