How can I cycle a USB device from C#?

前端 未结 2 660
感动是毒
感动是毒 2020-12-13 17:08

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://ww

2条回答
  •  囚心锁ツ
    2020-12-13 17:39

    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();
    

提交回复
热议问题