How to get something that could uniquely identify a cdrom by c#

Dudu 161 Reputation points

I need some c# code that can get something such as serial number or ID that can uniquely identify the fixed cdrom or usb cdrom.


An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,209 questions
0 comments No comments
{count} votes

Accepted answer
  1. Timon Yang-MSFT 9,571 Reputation points

    Can PNPDeviceID meet your requirements?

            ManagementObjectSearcher searcher =  
                   new ManagementObjectSearcher("root\\CIMV2",  
                   "SELECT * FROM Win32_DiskDrive");  
            foreach (ManagementObject queryObj in searcher.Get())  
                Console.WriteLine("PNPDeviceID: {0}", queryObj["PNPDeviceID"]);  

    If it is a CD, PNPDeviceID may be possible, but if the device is a usb device, then PNPDeviceID is not feasible, see this link for details:
    is pnpdeviceid of video card adapter unique
    Assigning a globally unique identifier to each device. I think this may require manufacturers to do this, but they don’t seem to have done so at present, and it seems unlikely that we can do this with code.
    In addition, if you want to get the SerialNumber, please look at this class: Win32_CDROMDrive class
    Just modify the above query statement and property name.
    But I don't have a CD so I haven't tested it yet.

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

0 additional answers

Sort by: Most helpful