How to detect using c# if a pendrive is plugged into a USB port?

前端 未结 4 1386
孤街浪徒
孤街浪徒 2020-12-04 16:52

Is there a way to find out when in a LAN anyone plugs in a pendrive to the USB port? Programatically (in C# preferably) or through some tool. Basically I\'d imagine a clien

4条回答
  •  渐次进展
    2020-12-04 17:54

    Also check out the registry where all information is stored about the usb devices. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB

    You can hook into changes of that key in the registry and act upon that.

    This free utility are a big help when pooking around: http://www.nirsoft.net/utils/usb_devices_view.html

    You can select a usb-drive, choose to open the registry key for that drive and enable/disable the device and a lot more.

    In the registry you can see if the device is connected, if it's of massstorage type and other interresting information. Its easy to filter the regkeys to just get usb-massstorage drives and then hook into and wait for changes (connect/disconnect).

    With Windows Management Instrumentation you can register to recieve Registry events: http://msdn.microsoft.com/en-us/library/aa393035(VS.85).aspx

    Check out System.Management in .Net

提交回复
热议问题