Close CD Tray with VBScript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • helraizer1
    New Member
    • Mar 2007
    • 118

    Close CD Tray with VBScript

    Hey, hey.

    I have written a script in VB to open the CD Tray

    Code:
    <script language="VBScript">
    <!--
    Sub Eject()
    Set oWMP = CreateObject("WMPlayer.OCX.7" )
    Set colCDROMs = oWMP.cdromCollection
    
    if colCDROMs.Count >= 1 then
            For i = 0 to colCDROMs.Count - 1
                    colCDROMs.Item(i).Eject
            Next ' cdrom
    End If
     End Sub
    -->
    </script>
    and have got it to run on the click of a button.

    Any ideas on how, using the same Idea (or a completely different one) I would get the VBScript to close the CD Tray again?

    Sam
  • cbbibleboy
    New Member
    • Apr 2007
    • 29

    #2
    Sadly, I'm not sure that it's actually possible using the same way as you specified. However, you could always write your own .ocx file and load that the same way as you did the other. :)

    Comment

    • helraizer1
      New Member
      • Mar 2007
      • 118

      #3
      I managed to do it. Using the same code;

      Code:
      <script language="VBScript">
      <!--
      Sub Close()
      Set oWMP = CreateObject("WMPlayer.OCX.7" )
      Set colCDROMs = oWMP.cdromCollection
      
      if colCDROMs.Count >= 1 then
              For i = 0 to colCDROMs.Count - 1
                      colCDROMs.Item(i).Eject
              Next ' cdrom
      	
      	For i = 0 to colCDROMs.Count - 1
      		colCDROMs.Item(i).Eject
      	Next
      End If
       End Sub
      -->
      </script>
      This repeated section at the end of the code closes the CD tray.

      Sam

      Comment

      • VIJAY SHANKAR
        New Member
        • Sep 2013
        • 1

        #4
        Easy way to open cd drive with three line Statements

        Easy way to open cd drive with three line Statements :
        Code:
        Set creatingwscript = WScript.CreateObject("wscript.Shell")
        Set play = CreateObject("WMPlayer.ocx")
        play.cdromCollection.item(0).Eject()
        1. Open notepad
        2. Paste the above Visual Basic Code
        3. Save the notepad with (any name).vbs format
        4. Double Click to see ur cd drive tray to open.



        by ur >Just

        Comment

        • kindanew99
          New Member
          • Dec 2013
          • 1

          #5
          Dim ts
          Dim strDriveLetter
          Dim intDriveLetter
          Dim fs 'As Scripting.FileS ystemObject
          Const CDROM = 4
          On Error Resume Next
          Set fs = CreateObject("S cripting.FileSy stemObject")
          strDriveLetter = ""
          For intDriveLetter = Asc("A") To Asc("Z")
          Err.Clear
          If fs.GetDrive(Chr (intDriveLetter )).DriveType = CDROM Then
          If Err.Number = 0 Then
          strDriveLetter = Chr(intDriveLet ter)
          Exit For
          End If
          End If
          Next
          Set oWMP = CreateObject("W MPlayer.OCX.7" )
          Set colCDROMs = oWMP.cdromColle ction

          if colCDROMs.Count >= 1 then
          For i = 0 to colCDROMs.Count - 1
          colCDROMs.Item( i).Eject
          Next ' cdrom

          For i = 0 to colCDROMs.Count - 1
          colCDROMs.Item( i).Eject
          Next
          set owmp = nothing
          set colCDROMs = nothing
          end if

          Comment

          Working...