Elder Hyde said:
Ask google mate, ask google.
I asked him and he gave me this:
http://www.codeguru.com/system/cdr.html
Except that's not in C#.
Try the following code fragment:
public bool Eject()
{
if (((int) _handle != -1) && ((int) _handle != 0))
{
uint Dummy = 0;
if (DeviceIoControl(_handle, IOCTL_STORAGE_EJECT_MEDIA, IntPtr.Zero,
0, IntPtr.Zero, 0, ref Dummy, IntPtr.Zero) != 0)
return true;
}
return false;
}
Get the handle with:
IntPtr _handle = CreateFile(@"\\.\" + _driveLetter + ':', GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0,
IntPtr.Zero);
and remember to close it when you're finished with a call to CloseHandle().
Here are the imports:
[System.Runtime.InteropServices.DllImport("Kernel32.dll",
SetLastError=true)]
private extern static int DeviceIoControl(IntPtr hDevice, uint
IoControlCode,
IntPtr lpInBuffer, uint InBufferSize,
IntPtr lpOutBuffer, uint nOutBufferSize,
ref uint lpBytesReturned,
IntPtr lpOverlapped);
[System.Runtime.InteropServices.DllImport("Kernel32.dll",
SetLastError=true)]
private extern static IntPtr CreateFile(string FileName, uint DesiredAccess,
uint ShareMode, IntPtr lpSecurityAttributes,
uint CreationDisposition, uint dwFlagsAndAttributes,
IntPtr hTemplateFile);
[System.Runtime.InteropServices.DllImport("Kernel32.dll",
SetLastError=true)]
private extern static int CloseHandle(IntPtr hObject);
private const uint IOCTL_STORAGE_EJECT_MEDIA = 0x002D4808;
I hope this helps...
Stuart Mackellar.