i was wondering if there was any code that can eject a disc drive when you click a button on a form.
im using VB.net 2003
Printable View
i was wondering if there was any code that can eject a disc drive when you click a button on a form.
im using VB.net 2003
Hey FireKnox,
I found a post similar to what you're looking for. The post title is "How to keep the door closed", but they also show the code to open it.
Link
~Crush
thank you for the find it helped me alot
Just requires one Declaration and one MCISendString command...
VB Code:
'function declaration Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _ (ByVal lpstrCommand As String, _ ByVal lpstrReturnString As String, _ ByVal uReturnLength As Int32, _ ByVal hwndCallback As Int32) As Int32 'opens cd tray mciSendString("set CDAudio door open", Nothing, 127, 0) 'closes cd tray mciSendString("set CDAudio door closed", Nothing, 127, 0)
That works great, Do u know how to open more then one disc drive though, and close it to.
Well the second parameter of the function is where you would pass in the device ID, and I would imagine that would require some sort of other declaration in order to get that...
**EDIT - actually, it looks as if it seems to be assigned only after the device is open??
http://msdn.microsoft.com/library/de...win32_open.asp
Found it here: http://www.geekpedia.com/tutorial174...y-in-.NET.html
You can send an open command with the drive letter and an alias, then use that alias in the set command. Below is an example of opening an "F:" drive
VB Code:
'replace "F:" with the drive letter you wish to open mciSendString("open F: type CDAudio alias driveF", Nothing, 0, Nothing) mciSendString("set driveF door open", Nothing, 0, 0)
**EDIT - and if you are wondering how you can get the drive letters, check out my codebank submission on using WMI, it would be the Win32_CDROMDrive WMI class, and the Property is "Drive" that returns the drive letter. Or check out this thread.
I think he is using 2005. So getting drive letter is something very easy. I would like to use this code ..
VB Code:
Dim drives() As IO.DriveInfo = IO.DriveInfo.GetDrives() For Each drive As IO.DriveInfo In drives If drive.DriveType = IO.DriveType.CDRom And drive.IsReady Then MessageBox.Show(drive.Name) End If Next
Drive.IsReady can be done with DeviceIOControl. It is not trivial...
See the attached project. With it you can find out:
Is the tray in or out
What media is in the drive (cdrom, cdr, cdrw, dvdrom, dvdram, dvd..., hd-dvd, blu-ray)
What media the drive can read/burn.
Readiness of the drive: NoDisc, Drive is Ready, Drive is Becoming Ready, Drive is not Ready.
To use deviceIOControl you have to get a handle to the drive. This is the only thing that can take time - if the drive is spinning up or "becoming ready", then you wont get the handle until the drive becomes ready. Once you have the handle, you can ask the drive if it is ready and get an immediate answer even when it is spinning up.
I've pulled the code from a wrapper I'm making for the windows XP IMAPI service. It will let you burn data and audio cds. I'm using deviceIOControl to get extra information that IMAPI lacks or that is broken in IMAPI. DriveReadiness is one such thing.
Vista is going to have IMAPI2, which supports dvd burning and is far friendlier. IMAPI2 is extensible, so that support for future drive types can be added - it just wraps deviceIOControl to do this.
Hum .. Thanks