c#读取win7下的便携式设备 如安卓设备中的文件

win7下手机usb插入电脑 会在便携式设备下面出现设备的名字 使用DriveInfo不能识别该设备 请教大神通过什么方法识别该设备

可以使用 System.IO.DriveInfo 类来识别本地磁盘驱动器和网络共享。但是它不能识别 USB 设备。可以使用 WMI (Windows Management Instrumentation) 来识别 USB 设备。可以使用 C# 中的 ManagementObjectSearcher 类来查询 WMI 数据,并通过查询 "Win32_DiskDrive" 或 "Win32_USBHub" 类来识别 USB 设备。

using (var searcher = new ManagementObjectSearcher(@"SELECT * FROM Win32_DiskDrive"))
{
    foreach (var item in searcher.Get())
    {
        Console.WriteLine("Device ID: {0}", item["DeviceID"]);
        Console.WriteLine("Caption: {0}", item["Caption"]);
    }
}

此代码将列出所有磁盘驱动器的设备ID和说明。可以使用相似的代码来查询 Win32_USBHub 类来识别 USB 设备。