Results 1 to 10 of 10

Thread: [02/03] Disc Drive

  1. #1

    Thread Starter
    Hyperactive Member FireKnox101's Avatar
    Join Date
    Aug 2005
    Location
    Snohomish,Washington
    Posts
    301

    Question [02/03] Disc Drive

    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

    Im currently using: VB.NET 2003, And VB 2005 Express
    My Projects
    Form Them Show Keypress In App
    Simple Ping Control

  2. #2
    Addicted Member Crushinator's Avatar
    Join Date
    Jan 2006
    Location
    The Dark Side of the Moon, MD
    Posts
    179

    Re: [02/03] Disc Drive

    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
    Using Framework 2.0, VB.Net 2005.

  3. #3

    Thread Starter
    Hyperactive Member FireKnox101's Avatar
    Join Date
    Aug 2005
    Location
    Snohomish,Washington
    Posts
    301

    Re: [02/03] Disc Drive

    thank you for the find it helped me alot

    Im currently using: VB.NET 2003, And VB 2005 Express
    My Projects
    Form Them Show Keypress In App
    Simple Ping Control

  4. #4
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [02/03] Disc Drive

    Just requires one Declaration and one MCISendString command...
    VB Code:
    1. 'function declaration
    2. Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
    3.           (ByVal lpstrCommand As String, _
    4.           ByVal lpstrReturnString As String, _
    5.           ByVal uReturnLength As Int32, _
    6.           ByVal hwndCallback As Int32) As Int32
    7.  
    8. 'opens cd tray
    9. mciSendString("set CDAudio door open", Nothing, 127, 0)
    10.  
    11. 'closes cd tray
    12. mciSendString("set CDAudio door closed", Nothing, 127, 0)
    Last edited by gigemboy; Apr 9th, 2006 at 03:19 AM.

  5. #5

    Thread Starter
    Hyperactive Member FireKnox101's Avatar
    Join Date
    Aug 2005
    Location
    Snohomish,Washington
    Posts
    301

    Re: [02/03] Disc Drive

    That works great, Do u know how to open more then one disc drive though, and close it to.

    Im currently using: VB.NET 2003, And VB 2005 Express
    My Projects
    Form Them Show Keypress In App
    Simple Ping Control

  6. #6
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [02/03] Disc Drive

    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

  7. #7
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: [02/03] Disc Drive

    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:
    1. 'replace "F:" with the drive letter you wish to open
    2. mciSendString("open F: type CDAudio alias driveF", Nothing, 0, Nothing)
    3. 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.
    Last edited by gigemboy; Apr 9th, 2006 at 03:58 AM.

  8. #8
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Smile Re: [02/03] Disc Drive

    I think he is using 2005. So getting drive letter is something very easy. I would like to use this code ..

    VB Code:
    1. Dim drives() As IO.DriveInfo = IO.DriveInfo.GetDrives()
    2.         For Each drive As IO.DriveInfo In drives
    3.             If drive.DriveType = IO.DriveType.CDRom And drive.IsReady Then
    4.                 MessageBox.Show(drive.Name)
    5.             End If
    6.         Next

  9. #9
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    297

    Re: [02/03] Disc Drive

    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.
    Attached Files Attached Files

  10. #10
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Re: [02/03] Disc Drive

    Hum .. Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width