how to determine USB Flash drive manufacturer?

后端 未结 8 1159
栀梦
栀梦 2020-12-06 07:14

I need my program to work only with certain USB Flash drives (from a single manufacturer) and ignore all other USB Flash drives (from any other manufacturers).

is it

相关标签:
8条回答
  • 2020-12-06 08:10

    Perhaps #usblib:

    http://www.icsharpcode.net/OpenSource/SharpUSBLib/

    0 讨论(0)
  • 2020-12-06 08:11

    Just in case anyone else is crazy enough to do this in C++-CLI, here's a port of smink's answer:

    using namespace System;
    using namespace System::Management;
    
    void GetUSBDeviceList()
    {
        try
        {
            ManagementObjectSearcher^ searcher =
                gcnew ManagementObjectSearcher("root\\CIMV2",
                "SELECT * FROM Win32_DiskDrive");
    
            for each (ManagementObject^ queryObj in searcher->Get())
            {
                Console::WriteLine("DeviceID: {0}", queryObj["DeviceID"]);
                Console::WriteLine("PNPDeviceID: {0}", queryObj["PNPDeviceID"]);
                Console::WriteLine("Manufacturer: {0}", queryObj["Manufacturer"]);
                Console::WriteLine("Model: {0}", queryObj["Model"]);
                for each (ManagementObject^ b in queryObj->GetRelated("Win32_DiskPartition"))
                {
                    Console::WriteLine("  Name: {0}", b["Name"]);
                    for each (ManagementBaseObject^ c in b->GetRelated("Win32_LogicalDisk"))
                    {
                        Console::WriteLine("    Name: {0}", c["Name"]); // here it will print drive letter
                    }
                }
                // ...
                Console::WriteLine("--------------------------------------------");
            }      
        }
        catch (ManagementException^ e)
        {
            Console::WriteLine(e->StackTrace);
        }
    
        Console::ReadLine();
    }
    

    Note: I had to manually add a reference to the System.Management library in my porject properties.

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