Open/Close CD Tray?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
NexxTech
Newbie
Posts: 5
Joined: Tue Nov 11, 2008 11:40 pm

Open/Close CD Tray?

Post by NexxTech » Thu Nov 13, 2008 9:21 pm

Is it possible to open/close the CD tray from a macro? I looked around and couldn't find it - thought I'd ask just in case I missed something.

Thanks! :)

User avatar
JRL
Automation Wizard
Posts: 3517
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Nov 13, 2008 11:47 pm

I didn't find a way to close but this I found this vbscript that can open my cd tray. This could most likely be cleaned up and made to run through Macro Scheduler by someone good with VBScripting.

Code: Select all

Let>file1=%temp_dir%cdeject.vbs
IfFileExists>File1
DeleteFile>file1
EndIf
WriteLn>file1,wres,Set oWMP = CreateObject("WMPlayer.OCX.7" )
WriteLn>file1,wres,Set colCDROMs = oWMP.cdromCollection
WriteLn>file1,wres,
WriteLn>file1,wres,if colCDROMs.Count >= 1 then
WriteLn>file1,wres,        For i = 0 to colCDROMs.Count - 1
WriteLn>file1,wres,                colCDROMs.Item(i).Eject
WriteLn>file1,wres,        Next ' cdrom
WriteLn>file1,wres,End If
Wait>0.5
Let>rp_wait=1
Let>rp_windowmode=0
Run>cmd /c %file1%
DeleteFile>file1
Last edited by JRL on Fri Nov 14, 2008 5:33 am, edited 1 time in total.

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Nov 14, 2008 3:07 am

From what I found I believe that the same command will open if it is closed, and close if it is open. Note that some drives are not equipped to close automatically.

User avatar
Marcus Tettmar
Site Admin
Posts: 7391
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Nov 14, 2008 12:23 pm

JRL wrote:I didn't find a way to close but this I found this vbscript that can open my cd tray. This could most likely be cleaned up and made to run through Macro Scheduler by someone good with VBScripting.

Code: Select all

Let>file1=%temp_dir%cdeject.vbs
IfFileExists>File1
DeleteFile>file1
EndIf
WriteLn>file1,wres,Set oWMP = CreateObject("WMPlayer.OCX.7" )
WriteLn>file1,wres,Set colCDROMs = oWMP.cdromCollection
WriteLn>file1,wres,
WriteLn>file1,wres,if colCDROMs.Count >= 1 then
WriteLn>file1,wres,        For i = 0 to colCDROMs.Count - 1
WriteLn>file1,wres,                colCDROMs.Item(i).Eject
WriteLn>file1,wres,        Next ' cdrom
WriteLn>file1,wres,End If
Wait>0.5
Let>rp_wait=1
Let>rp_windowmode=0
Run>cmd /c %file1%
DeleteFile>file1
Here you go:

Code: Select all

VBSTART
Sub EjectTray
  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
VBEND

VBRun>EjectTray
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

NexxTech
Newbie
Posts: 5
Joined: Tue Nov 11, 2008 11:40 pm

Post by NexxTech » Fri Nov 14, 2008 5:10 pm

Thanks you so much! :) works perfect! the support in this foum is amazing! :)

Aaron
Pro Scripter
Posts: 113
Joined: Mon Apr 09, 2007 1:35 am
Location: Wyoming

Post by Aaron » Thu Jan 08, 2009 3:22 am

As to your first question of open and close
add another - colCDROMs.Item(i).Eject
if you want to loop, use the do and loop at beginning and end
if you have two cd roms and just want the second one to open
use: For i = 1 to colCDROMs.Count - 1
instead of: For i = 0 to colCDROMs.Count - 1


VBSTART
Sub EjectTray
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
colCDROMs.Item(i).Eject
Next ' cdrom
End If
End Sub
VBEND

VBRun>EjectTray
Aaron

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts