views:

1533

answers:

1

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.

I have read this:

http://www.tech-archive.net/Archive/Development/microsoft.public.development.device.drivers/2005-02/1292.html

I do not understand it.

This has been mentioned in other USB related posts:

http://www.codeproject.com/KB/system/DriveDetector.aspx

It is not relevant to my problem.

+4  A: 

Got it working by using a commandline tool called devcon, which I then called from code.

Dropped devcon.exe into one of the system paths so it works everywhere.

Devcon: devcon

called: DEVCON Remove usb"MI_01"

then called: DEVCON rescan

code:

 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();
callisto
It would be good if you could add a link to devcon and some example code so other people can learn.
Kinlan
devcon at http://support.microsoft.com/kb/311272
callisto
I had a device (touchscreen controller) that I did something similar with, but I actually had to remove/rescan on the HUB for it to work. It may have been a crappy hub, 9and it was definitely a crappy driver) but the remove on the device still left it powered, and removing the hub actually cut the power.
Dolphin
I tried devcon, but I always get "access is denied" when using it from the command line. Win 7 pro. Any ideas why?
sipickles