C# how to know if removable disk is a usb drive, or a sd card?

前端 未结 2 1559
野的像风
野的像风 2021-02-19 04:55

Windows 7 platform, C#

I use the following statement to list all drives:

DriveInfo[] drives = DriveInfo.GetDrives();

then I can use Dri

2条回答
  •  我寻月下人不归
    2021-02-19 05:26

    I had to check for USB-Devices in an older project and solved it like this:

     Win32.DEV_BROADCAST_DEVICEINTERFACE deviceInterface;
     deviceInterface = (Win32.DEV_BROADCAST_DEVICEINTERFACE)
     string name = new string(deviceInterface.dbcc_name);
     Guid g = new Guid(deviceInterface.dbcc_classguid);
     if (g.ToString() == "a5dcbf10-6530-11d2-901f-00c04fb951ed")
     {*DO SOMETHING*}
    

    I get the GUID and check if the devices GUID is the USB-GUID.

提交回复
热议问题