Hi Greg
You can use WMI, here is a sample that checks to see if a CD-ROM is in any
CD drive.
-- Begin Code --
using System;
using System.Management;
class App
{
public static void Main()
{
SelectQuery query = new SelectQuery( "select * from win32_logicaldisk
where drivetype=5" );
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach( ManagementObject mo in searcher.Get() )
{
// If both properties are null I suppose there's no CD
if( ( mo["volumename"] != null ) || ( mo["volumeserialnumber"] !=
null ) )
{
Console.WriteLine( "CD is named: {0}", mo["volumename"] );
Console.WriteLine( "CD Serial Number: {0}",
mo["volumeserialnumber"] );
}
else
{
Console.WriteLine( "No CD in Unit" );
}
}
// Here to stop app from closing
Console.WriteLine( "\nPress Return to exit." );
Console.Read();
}
}
--End Code--
Hope this helps
Publicjoe
C# Tutorial at
http://www.publicjoe.f9.co.uk/csharp/tut.html
C# Ebook at
http://www.publicjoe.f9.co.uk/csharp/samples/ebook.html
VB Tutorial at
http://www.publicjoe.f9.co.uk/vbnet/vbnet.html
VB Ebook at
http://www.publicjoe.f9.co.uk/vbnet/samples/ebook.html
Mirrors at
http://www.dowhileloop.com/publicjoe/ and
http://www.publicjoe.justbe.com/
Useful Articles at
http://www.madsally.co.uk
GregT said:
Is there a way to programmatically identify a local CD drive/drives from a
local machine. Currently, I am calling
System.IO.Directory.GetLogicalDrives() - but this lists all the drives on the
local machine. What is the best way to identify the CD drive(s)?