1

I would like to get the number of total sectors on a medium inserted in CD-ROM drive. Is there method for this in C#? I've checked the Management class in .NET but that does not seem to have a method.

Mat
  • 202,337
  • 40
  • 393
  • 406
Mert Sevinc
  • 929
  • 1
  • 8
  • 25

1 Answers1

2

The Windows API function DeviceIoControl will get that information for you. Unfortunately, there's no simple wrapper for it in the .NET libraries.

This sample shows how to do what you want in C. Translating that to C# is non-trivial, but you might find some helpful pointers here: Calling DeviceIoControl from C# with IOCTL_DVD_* Control Codes

Community
  • 1
  • 1
Jim Mischel
  • 131,090
  • 20
  • 188
  • 351
  • The example you are referring to uses Disk_Geometry structure, which returns only the used sectors on a disc, not a disc's total capacity. I need to learn the full capacity. How can I figure this out? – Mert Sevinc Feb 06 '11 at 13:07
  • @Mert: Take a look at http://stackoverflow.com/questions/82993/windows-cd-burning-api. The accepted answer has a C++ sample that uses the Image Mastering API (http://msdn.microsoft.com/en-us/library/aa366450(v=VS.85).aspx). There's a sample of using it from C# at http://www.codeproject.com/KB/miscctrl/imapi2.aspx. – Jim Mischel Feb 06 '11 at 14:13
  • Unfortunately, that API only works when the disc is burnable. Otherwise, it throws an exception. There's gotta be an easy way to do this. – Mert Sevinc Feb 06 '11 at 15:17