Identify USB flash drive in C#
<p>I need an ID that uniquely identifies an USB flash drive. The ID should already exists on the flash drive, so that it is the same ID on every PC I plug it in. It seems that the PNPDeviceID is not unique. Can anyone proof that? And if its not unique, is there another ID to identify an USB flash drive uniquely?</p>

<p>I´ve already read those answers but they don´t help me to solve my problem:</p>

<p><a href="https://stackoverflow.com/questions/4043453/pnpdeviceid-format">PNPDeviceID Format</a></p>

<p><a href="https://stackoverflow.com/questions/11810046/is-the-pnpdeviceid-unique">Is the PNPDeviceID unique</a></p>

<p><a href="https://stackoverflow.com/questions/17997284/c-net-usb-device-persistent-identifier">c#.NET USB device persistent identifier</a></p>

<p><strong>EDIT:</strong> </p>

<p>Here´s what I´ve coded to get the ID.</p>

<pre><code>    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Management;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApplication6
    {
        class USBDeviceInfo
        {
            public USBDeviceInfo(string deviceID, string pnpDeviceID, string description)
            {
                this.DeviceID = deviceID;
                this.PnpDeviceID = pnpDeviceID;
                this.Description = description;
            }
            public string DeviceID { get; private set; }
            public string PnpDeviceID { get; private set; }
            public string Description { get; private set; }
        }

        class Program
        {
            static List&lt;string&gt; Drives = new List&lt;string&gt;();

            static List&lt;USBDeviceInfo&gt; GetUSBDevices()
            {
                List&lt;USBDeviceInfo&gt; devices = new List&lt;USBDeviceInfo&gt;();

                ManagementObjectCollection collection;
                using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_USBHub"))
                    collection = searcher.Get();

                foreach (var device in collection)
                {
                    devices.Add(new USBDeviceInfo(
                    (string)device.GetPropertyValue("DeviceID"),
                    (string)device.GetPropertyValue("PNPDeviceID"),
                    (string)device.GetPropertyValue("Description")
                    ));
                }
                collection.Dispose();
                return devices;
            }

            static void Main(string[] args)
            {
                var usbDevices = GetUSBDevices();

                foreach (var usbDevice in usbDevices)
                {
                    // USB-Massenspeichergerät means USB mass storage device in english
                    if (usbDevice.Description.Equals("USB-Massenspeichergerät"))
                    {
                        Console.WriteLine(usbDevice.PnpDeviceID);           
                    }
                }
                Console.ReadKey();
            }
        }
    }
</code></pre>

<p>And this are some example IDs that I get from two different USB flash drives of the same vendor and exactly the same type (it doesn´t matter if I take the DeviceID or the PNPDeviceID, they are the same):</p>

<p><a href="https://i.stack.imgur.com/8vp27.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8vp27.png" alt="enter image description here"></a></p>

<p>As you can see the VID and the PID are equivalent. The only difference between them is the number after the '\'. As I read in the answer here <a href="https://stackoverflow.com/questions/4043453/pnpdeviceid-format">PNPDeviceID Format</a> , it seems to be only the device instance, that is created by the system to identify the flash drive. So after reading this answer I´m not sure if thats unique.</p>