🟣 C# / .NET 6+

Get CD/DVD Drives Report (C#)

Queries Win32_CDROMDrive via WMI (System.Management) and prints CD/DVD Drives to the console.

By WindowsScripting.com · 959 B
GetCDROMDriveReport.cs
// GetCDROMDriveReport.cs
//
// Reports CD/DVD Drives via WMI (Win32_CDROMDrive).
//
// Requires the System.Management package:
//   dotnet new console -o CDROMDriveReport
//   dotnet add package System.Management
//   (replace the generated Program.cs with this file, then dotnet run)
// On .NET Framework, System.Management is already available — just
// add a reference to it in your project.

using System;
using System.Management;

var searcher = new ManagementObjectSearcher("SELECT Name, Drive, MediaType FROM Win32_CDROMDrive");
int count = 0;

foreach (ManagementObject item in searcher.Get())
{
    Console.WriteLine($"Name: {item["Name"]}");
    Console.WriteLine($"Drive: {item["Drive"]}");
    Console.WriteLine($"MediaType: {item["MediaType"]}");
    Console.WriteLine(new string('-', 40));
    count++;
}

if (count == 0)
{
    Console.WriteLine("No CD/DVD Drives found.");
}
else
{
    Console.WriteLine($"\n{count} CD/DVD Drives found.");
}