For a WPF-application i'm programming using c#, i want to check if a specific USB device (in this case it's a Philips GoGear Vibe) is connected to the PC.

Basically I want a function that checks this and returns a bool.

I would also lik to be able to find the drive letter to which this USB device is connected.

I've googled this but none of the answers really satisfies what I need.

有帮助吗?

解决方案

go look at these links.

USB Device Connected C# detect usb device ClassCode (usb device type) http://social.msdn.microsoft.com/Forums/en-US/e6f074b3-31ae-4d9d-9aee-6eda728b17f6/detecting-usb-device-insertion-in-c

That should help you with your check to see if the drive was connected. To see the drives letter and path, put an event on in the solution from the link i added and just use

DriveInfo[] allDrives = DriveInfo.GetDrives();

note that you need to do this as an initialisation for your drives, just compare the initialized drives and the new drives list on event and the odd one out will be your drive letter. there are other ways of doing this though, that one has many flaws in it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top