• Using WMI to get CDROM Info in C#

    Posted on October 24, 2012 by in Dotnet Tips & Tricks, Tips & Tricks

    public static void RetrieveCDROMProps()
    {
        //initialize the select query with command text
        SelectQuery query = new SelectQuery(@"Select * from Win32_CDROMDrive");
    
        //initialize the searcher with the query it is supposed to execute
        using (ManagementObjectSearcher searcher = new
        ManagementObjectSearcher(query))
        {
            //execute the query
            foreach (ManagementObject process in searcher.Get())
            {
                //print CD ROM properties
                Console.WriteLine("/*********CD ROM Drive Information ***************/");
                Console.WriteLine("{0}{1}", "Name:", process["Name"]);
                Console.WriteLine("{0}{1}", "Caption:", process["Caption"]);
                Console.WriteLine("{0}{1}", "DeviceID:", process["DeviceID"]);
                Console.WriteLine("{0}{1}", "Description:", process["Description"]);
            }
        }
    }
    

    get CDROM Info 1

    List Of Properties

    Data Type Property Name
    uint16 Availability
    uint16 Capabilities[]
    string CapabilityDescriptions[]
    string Caption
    string CompressionMethod
    uint32 ConfigManagerErrorCode
    boolean ConfigManagerUserConfig
    string CreationClassName
    uint64 DefaultBlockSize
    string Description
    string DeviceID
    string Drive
    boolean DriveIntegrity
    boolean ErrorCleared
    string ErrorDescription
    string ErrorMethodology
    uint16 FileSystemFlags
    uint32 FileSystemFlagsEx
    string Id
    datetime InstallDate
    uint32 LastErrorCode
    string Manufacturer
    uint64 MaxBlockSize
    uint32 MaximumComponentLength
    uint64 MaxMediaSize
    boolean MediaLoaded
    string MediaType
    string MfrAssignedRevisionLevel
    uint64 MinBlockSize
    string Name
    boolean NeedsCleaning
    uint32 NumberOfMediaSupported
    string PNPDeviceID
    uint16 PowerManagementCapabilities[]
    boolean PowerManagementSupported
    string RevisionLevel
    uint32 SCSIBus
    uint16 SCSILogicalUnit
    uint16 SCSIPort
    uint16 SCSITargetId
    uint16 SerialNumber
    uint64 Size
    string Status
    uint16 StatusInfo
    string SystemCreationClassName
    string SystemName
    real64 TransferRate
    string VolumeName
    string VolumeSerialNumber
    Be Sociable, Share!
      Post Tagged with , ,

    Written by

    Software architect with over 10 years of proven experience in designing & developing n-tier and web based software applications, for Finance, Telecommunication, Manufacturing, Internet and other Commercial industries. He believes that success depends on one's ability to integrate multiple technologies to solve a simple as well as complicated problem.

    View all articles by

    Email : [email protected]

    One Responseso far.

    1. Santosh says:

      Nice article Venu Gopal.
      I have an issue, I assume you can help in this case.

      “How to tell if CD/DVD drive tray is open?” in other words – “I want to access the drive tray status – open or closed” I have tried with following code
      SelectQuery query = new SelectQuery(@”Select * from Win32_CDROMDrive”);
      ManagementObjectSearcher objSearcher = new ManagementObjectSearcher(query);
      foreach (ManagementObject mo in objSearcher.Get())
      {
      foreach (PropertyData prop in mo.Properties)
      this.listBox1.BeginInvoke(new Action(p => listBox1.Items.Add(p.Name + “-” + p.Value)), prop);
      }

      specially looked for MediaLoaded property. But it is not useful to my question – “I want to access the drive tray status – open or closed”

      Please help…

    Leave a Reply