Check wheather CD is inside your CD-ROM

Before coding this program you have to add reference of Management.
These code will detect a CD in your CD-ROM

using System;
using System.Management;

class MyCDAPP
public static void Main()
SelectQuery query = new SelectQuery("select * from win32_logicaldisk where drivetype=5");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject mob in searcher.Get())
// if both values are null,there is no CD.
if ((mob["volumename"] != null) || (mob["volumeserialnumber"] != null))
Console.WriteLine("Name : {0}", mob["volumename"]);
Console.WriteLine("CD Serial Number: {0}", mob["volumeserialnumber"]);
Console.WriteLine("There is no CD");

// To close the form.
Console.WriteLine("\nPress Return to exit.");

You can apply this code in any project.


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: