By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,918 Members | 1,557 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,918 IT Pros & Developers. It's quick & easy.

Close CD Tray with VBScript

100+
P: 118
Hey, hey.

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

Expand|Select|Wrap|Line Numbers
  1. <script language="VBScript">
  2. <!--
  3. Sub Eject()
  4. Set oWMP = CreateObject("WMPlayer.OCX.7" )
  5. Set colCDROMs = oWMP.cdromCollection
  6.  
  7. if colCDROMs.Count >= 1 then
  8.         For i = 0 to colCDROMs.Count - 1
  9.                 colCDROMs.Item(i).Eject
  10.         Next ' cdrom
  11. End If
  12.  End Sub
  13. -->
  14. </script>
  15.  
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
Apr 27 '07 #1
Share this Question
Share on Google+
4 Replies


P: 29
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. :)
Apr 28 '07 #2

100+
P: 118
I managed to do it. Using the same code;

Expand|Select|Wrap|Line Numbers
  1. <script language="VBScript">
  2. <!--
  3. Sub Close()
  4. Set oWMP = CreateObject("WMPlayer.OCX.7" )
  5. Set colCDROMs = oWMP.cdromCollection
  6.  
  7. if colCDROMs.Count >= 1 then
  8.         For i = 0 to colCDROMs.Count - 1
  9.                 colCDROMs.Item(i).Eject
  10.         Next ' cdrom
  11.  
  12.     For i = 0 to colCDROMs.Count - 1
  13.         colCDROMs.Item(i).Eject
  14.     Next
  15. End If
  16.  End Sub
  17. -->
  18. </script>
  19.  
This repeated section at the end of the code closes the CD tray.

Sam
Apr 30 '07 #3

P: 1
Easy way to open cd drive with three line Statements :
Expand|Select|Wrap|Line Numbers
  1. Set creatingwscript = WScript.CreateObject("wscript.Shell")
  2. Set play = CreateObject("WMPlayer.ocx")
  3. play.cdromCollection.item(0).Eject()
  4.  
  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
Sep 21 '13 #4

P: 1
Dim ts
Dim strDriveLetter
Dim intDriveLetter
Dim fs 'As Scripting.FileSystemObject
Const CDROM = 4
On Error Resume Next
Set fs = CreateObject("Scripting.FileSystemObject")
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(intDriveLetter)
Exit For
End If
End If
Next
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
set owmp = nothing
set colCDROMs = nothing
end if
Dec 7 '13 #5

Post your reply

Sign in to post your reply or Sign up for a free account.