Results 1 to 21 of 21

Thread: using cd drive id to open/close cd tray

  1. #1

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512

    using cd drive id to open/close cd tray

    Does anyone knoe how to manipulate the cd rom drives if you have the cd drive id (0,1,0) (HA,TGT,LUN) for example.

    i want to open and close the cd tray via code but i dont have the drive letter only the cd drives ids. Any ideas anyone?

    Thanks in advance
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  2. #2
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    How did you get the serial numbers from these CD's?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  3. #3
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    WELL

    Possibly the long way...

    Use Drive List to get all Drives on system...

    Loop each drive...

    Get SN for each drive

    Compare SN against number you say you know already...

    If match open Tray
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    And here's how to retrieve the serail number, just send down the drive letter as I mentioned in the loop earlier :

    http://www.vbworld.com/api/tip29.html
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  5. #5
    Addicted Member Martin Wilson's Avatar
    Join Date
    Mar 2002
    Location
    :)
    Posts
    236
    Err...he doesn't have there serial number...he has the drive ID.
    What is the answer to this question?

  6. #6
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Well

    Originally posted by Martin Wilson
    Err...he doesn't have there serial number...he has the drive ID.
    Guess I have to read better...

    It's been a long day
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  7. #7

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    hehehe, Back in your basket James.....back in your basket!

    Yes unfortunately its the drive id i have (0,1,0) (as listed in control panel). I actually got these numbers from a 3rd party dll written in delphi that im calling within my app. I just have no idea hoe to get the drive letter using this info! I also have the vendor and product id (eg "SAMSUNG CDR/RW G406") if thats any help!
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  8. #8
    Hyperactive Member ZeroCool's Avatar
    Join Date
    Feb 2002
    Location
    In front of my computer
    Posts
    423
    This Code Will Get A The Drive Letters of A Certain Type of Drive

    Put this in a module:

    VB Code:
    1. 'Drive Constants
    2. Public Const DRIVE_FIXED = 3
    3. Public Const DRIVE_REMOTE = 4
    4. Public Const DRIVE_REMOVABLE = 2
    5. Public Const DRIVE_UNKNOWN = 0
    6.  
    7. Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
    8.  
    9. Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
    10.  
    11. Public Function GetAllDrives() As Collection
    12. Dim lpBuffer As String
    13. Set GetAllDrives = New Collection
    14. lpBuffer = GetDriveString()
    15.  
    16. Do Until lpBuffer = Chr(0)
    17.    GetAllDrives.Add StripNulls(lpBuffer)
    18. Loop
    19. End Function
    20.  
    21.  
    22. Private Function GetDriveString() As String
    23. Dim sBuffer As String
    24.    sBuffer = Space$(26 * 4)
    25.    If GetLogicalDriveStrings(Len(sBuffer), sBuffer) Then
    26.       GetDriveString = Trim$(sBuffer)
    27.       End If
    28. End Function
    29.  
    30.  
    31. Private Function StripNulls(startstr As String) As String
    32. Dim pos As Long
    33. pos = InStr(startstr$, Chr$(0))
    34.   If pos Then
    35.       StripNulls = Mid$(startstr, 1, pos - 1)
    36.       startstr = Mid$(startstr, pos + 1, Len(startstr))
    37.       Exit Function
    38.     End If
    39. End Function
    40.  
    41. Public Function GetDriveLetters(DriveType As Integer) As Collection
    42. Set GetHardDrives = New Collection
    43. Dim I As Integer
    44. I = GetAllDrives.Count
    45. Do Until I = 0
    46. If GetDriveType(GetAllDrives(I)) = DriveType Then: GetDriveLetters.Add (GetAllDrives.Item(I))
    47. I = I - 1
    48. Loop
    49. End Function
    Visual Baisc 6 (SP5)
    Windows Xp

  9. #9

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Nice one ZeroCool but id like the drive name aswell (I already have this but) how do i know that lets say Drive F is my Plextor drive? The info i have is (HA,TGT,LUN), Drive ID ( PLEXTOR , CD-R PX-W2410A v1.03 (0:0:0)), Vendor (PLEXTOR) and Product ID ( CD-R PX-W2410A). But how do I know what the drive letter is for this drive when i have 2 or maybe 3 CDROMs? Thanks for your reply. I just have to tie up the drive letter i get from your code with the info i can already obtain!?
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  10. #10
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Code:
    Private Declare Function GetDriveType Lib "Kernel32" Alias "GetDriveTypeA" _
    (ByVal nDrive As String) As Long
    
    Private Declare Function GetVolumeInformation Lib "Kernel32" Alias "GetVolumeInformationA" _
    (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, _
    lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, _
    ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
    
    
    Private Sub Form_Load()
    
        Dim straryCDDrives() As String
        Dim intLetterCounter As Integer
        Dim intElementCounter As Integer
        Dim lngSerial As Long, strVolumnName As String
        
        intElementCounter = 0
        
        For intLetterCounter = 65 To 90
        
            If (GetDriveType(Chr(intLetterCounter) & ":\") = 5) Then
    
                ReDim Preserve straryCDDrives(1, intElementCounter)
                
                straryCDDrives(0, intElementCounter) = Chr(intLetterCounter) & ":\"
                
                strVolumnName = String(255, Chr(0))
                GetVolumeInformation Chr(intLetterCounter) & ":\", strVolumnName, 255, lngSerial, 0, 0, 0, 255
                
                straryCDDrives(1, intElementCounter) = Left(strVolumnName, InStr(1, strVolumnName, Chr(0)) - 1)
                
                intElementCounter = intElementCounter + 1
                
            End If
            
        Next
    
    End Sub
    This'll hold a multi-dementional array of cd drive letters & the drive names for you.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  11. #11
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Following on from that one then, you could use this to open a specific cd-rom tray based upon it's name rather than using it's id :
    Attached Files Attached Files

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  12. #12
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    So what exactly is the code to open the CD drive??
    Don't Rate my posts.

  13. #13
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    The code to open it is in these 2 lines, you need to use the mciSendString command for this one :
    Code:
    mciSendString "open " & Chr(intLetterCounter) & ": type cdaudio alias dooralias", vbNullString, 0, 0
    mciSendString "set dooralias door open", vbNullString, 0, 0
    If you're trying to use the above code as a test on your pc, I've told it to search and open the cd drive where the drive name / desciption is equal to the word "PLEXOR", if you comment out that if statement, you'll be able to see it work!

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  14. #14

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Alex, I'm gonna add you to my "Top Banana" list of cool people. Thats just what I wanted mate.....yum yum.

    Thanks a lot mate. If you want anything, just holler!!

    Cheers
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  15. #15
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    If you want anything, just holler!!
    Well now you mention it, if you can hook me up with Kirsten Dunst, that'd be fantastic !

    Glad to help out. Cheers

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  16. #16

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    I can hook u up with Kirsten Timberlake......shes similar but has a bigger ass (Dont tell her i said that Im already in trouble with her for pulling down her skirt for a surprise pic on her birthday!)
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  17. #17

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Hey Alex, one more question if you know the answer......
    In Nero when u burn a disc, if you havent inserted a CD it ask you to insert one, then waits.....once you put a cd in the drive it automatically continues with the burn. How can i detect a new cd has been put in the drive?
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  18. #18
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Each CD has a unique serial number burnt into it when it's first created by the manufacturer.

    When Nero does it, it checks the cd number, if it's different to the one it's just tried, it allows you to go ahead & burn the illegal program/porn collection/warez porogram whatever.

    As far as how to do this in vb - no idea whatsoever sorry you might want to try & ask that in the API forum....

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  19. #19

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    ok thanks.....nice examples you gave there
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  20. #20
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Okay I lied, god I'm too good at this, I even suprise myself!
    Note that I specify the D:\ drive in this which you might want to alter ...
    Code:
    Private Declare Function GetVolumeInformation Lib "Kernel32" Alias _
    "GetVolumeInformationA" (ByVal lpRootPathName As String, _
    ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, _
    lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, _
    lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, _
    ByVal nFileSystemNameSize As Long) As Long
    
    Private Sub Form_Load()
        Dim Serial As Long
        GetVolumeInformation "D:\", 0, 255, Serial, 0, 0, 0, 255
    
        MsgBox "The serial number of D:\ is " & Trim(Serial)
    End Sub

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  21. #21

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    yep, you are much too good at this....im gonna have to think of some harder questions! You should give up your dustman job and take up programming.
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

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