小编ban*_*ong的帖子

C#获取连接到PC的便携式设备

我试图在Windows 7上获取所有USB设备(包括便携式设备),现在我搜遍了所有并没有找到一个好的答案.

我试过这段代码:

static void Main(string[] args)
{
    //
    // Get an instance of the device manager
    //
    PortableDeviceApiLib.PortableDeviceManagerClass devMgr
        = new PortableDeviceApiLib.PortableDeviceManagerClass();

    //
    // Probe for number of devices
    //
    uint cDevices = 1;
    devMgr.GetDevices(null, ref cDevices);

    //
    // Re-allocate if needed
    //
    if (cDevices > 0)
    {
        string[] deviceIDs = new string[cDevices];
        devMgr.GetDevices(deviceIDs, ref cDevices);

        for (int ndxDevices = 0; ndxDevices < cDevices; ndxDevices++)
        {
            Console.WriteLine("Device[{0}]: {1}",
                    ndxDevices + 1, deviceIDs[ndxDevices]);
        }
    }
    else
    {
        Console.WriteLine("No WPD devices …
Run Code Online (Sandbox Code Playgroud)

c# connection usb wpd

5
推荐指数
1
解决办法
3488
查看次数

标签 统计

c# ×1

connection ×1

usb ×1

wpd ×1