Problem in accessing CD Drive in VB.Net 2.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • priyamtheone
    New Member
    • Sep 2007
    • 88

    Problem in accessing CD Drive in VB.Net 2.0

    Hi everyone, I'm focusing on a real tough problem that I hav been trying
    to solve since a long time. I'm trying to detect the Open or close status
    of the Cd drive door. I'm using mcisendstring function to query the
    status, mcisendstring(" Status CDAudio Mode"). This function returns
    the following values accordingly:
    "not ready", "paused", "playing", and "stopped" values.

    Some devices can return the additional "open", "parked", "recording" ,
    and "seeking" values.

    If there is a cd in the drive and the door is closed then it's almost easy
    to identify as "status CDAudio mode" returns a value anything other
    than "open". But the real problem is when the CD door is open the
    value returned by the mcisendstring function is "open". Again when the
    CD door is closed with no CD inside the function is returning the same
    value "open". There's no way I can distinguish the CD tray status
    programatically when the value returned is "open". Can anybody help
    me? Is there any way other than the mcisendstring function to
    query the CD door status? If yes then Plz provide me a code example.
  • TTCEric
    New Member
    • Jul 2008
    • 26

    #2
    If you know the drive letter assigned to the drive, why not check for the existence of files?

    Using My:
    Code:
    Dim szCDROM as String = "Z:\"
    IF My.Computer.FileSystem.GetFiles(szCDROM).Count  > 0 THEN
       msgbox "Drive must be closed. I see files!"
    END IF
    Although it might error out if you attempt a GetFiles on an open drive. Solution to that would be to use Try/Catch block.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      and you need to know the difference between door open and door being closed without a CD?
      Most things I have seen have been geared towards "is a cd in the drive or not"

      Comment

      • TTCEric
        New Member
        • Jul 2008
        • 26

        #4
        Does it make sense that the 'OPEN' condition is saying yes because it is querying the hardware driver which has a much tighter criteria of what it means to be open? So, the instant you ask, it will say yes until it realizes a spin and the shell (explorer) does its part. It might be a timing thing. The object your using is reporting what it knows at the time you ask. Know what I mean?

        Comment

        • priyamtheone
          New Member
          • Sep 2007
          • 88

          #5
          Originally posted by TTCEric
          If you know the drive letter assigned to the drive, why not check for the existence of files?

          Using My:
          Code:
          Dim szCDROM as String = "Z:\"
          IF My.Computer.FileSystem.GetFiles(szCDROM).Count  > 0 THEN
             msgbox "Drive must be closed. I see files!"
          END IF
          Although it might error out if you attempt a GetFiles on an open drive. Solution to that would be to use Try/Catch block.
          I don't hav any problem while there's a cd inside. The problem lies when there's no media in there. In that case using the code U provided will return 'False' i.e. no file(s) found, regardless of the cd door is open or closed. The problem still lies b'coz It won't tell me whether the tray is opened or not.

          Comment

          • Plater
            Recognized Expert Expert
            • Apr 2007
            • 7872

            #6
            Originally posted by priyamtheone
            I don't hav any problem while there's a cd inside. The problem lies when there's no media in there. In that case using the code U provided will return 'False' i.e. no file(s) found, regardless of the cd door is open or closed. The problem still lies b'coz It won't tell me whether the tray is opened or not.
            Well I did a LOT of playing around with this stuff and I couldn't figure a good way to determine if the tray was open or not. I would say is what you could do is force the tray to be either open or closed (i.e. send the eject signal probably be the best since some drives aren't capable of retracting the tray)

            Comment

            • priyamtheone
              New Member
              • Sep 2007
              • 88

              #7
              Originally posted by Plater
              Well I did a LOT of playing around with this stuff and I couldn't figure a good way to determine if the tray was open or not. I would say is what you could do is force the tray to be either open or closed (i.e. send the eject signal probably be the best since some drives aren't capable of retracting the tray)
              Well that's wut I hav thought at last. It seems there's no other option. I'm forcing the door to be opened if the status returned is OPEN. Thanx anyway to all of U for ur knowledgeshare. Regards.

              Comment

              • Jerrod
                New Member
                • Aug 2010
                • 1

                #8
                I too have been writing an app that deals with exactly the issue the original author faces. When my application loads, I force the CD drive door closed, then set the application state for the drawer to closed. From there I can manage the door from within the app.

                However, this approach would never work for a casual user because if they manually open the door, the app is now out of sync with the true state of the drive. Proper control, and the integrity of information displayed in the app, is lost.

                I have a feeling we might be out of luck as far as an easy way. If you right-click on a CD drive in ((My)Computer)W indows Explorer, the option to open the drawer is 'eject'. If you right-click on it when the door is open, the option does not change. I think it's unlikely the language provides functionality the operating system does not afford itself.

                Comment

                Working...