Get notification when a new drive is connected via USB or other means (C#)

前端 未结 4 688
余生分开走
余生分开走 2020-12-20 17:36

I need to detect when a new drive is plugged into a Windows system through a USB port, firewire port, etc. I am aware of the WM_DEVICECHANGE message, but this requires a win

相关标签:
4条回答
  • 2020-12-20 18:28

    This blogpost show how to handle system events, https://web.archive.org/web/1/http://blogs.techrepublic%2ecom%2ecom/howdoi/?p=135 maybe you can use it for the event that you want to handle

    0 讨论(0)
  • 2020-12-20 18:31

    You will need to subscribe to RegisterDeviceNotification, and bind it to a service status handle. See also http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/9ae4478a-1133-44ba-8a1c-3e4be3856e37.

    I'm not quite sure how to implement this, has been a long time ago.

    0 讨论(0)
  • 2020-12-20 18:31

    You may create a hidden window or run a service as it should work with a window handle or a service status handle.

    0 讨论(0)
  • 2020-12-20 18:33

    A windows service should do the trick

    Try reworking the CodeProject DriveDetector as a service and you should have what you need

    0 讨论(0)
提交回复
热议问题