1

I need to open and then after a few seconds, close the CD drive, with VBS. All I know now, is only to eject the drive with this code

Set oWMP = CreateObject("WMPlayer.OCX.7")
Set colCDROMs = oWMP.cdromCollection
if colCDROMs.Count >= 1 then
colCDROMs.Item(i).Eject
End If

a question this simple may seem dumb, but forgive me I'm not a programmer.

user152435
  • 113
  • 2
  • 7

2 Answers2

1

Give a try for this vbscript :

Option Explicit
'To open the CD-Rom
Call Open_Close_CD()
'Make a pause for 20 seconds and you can modify it for your needs
Call Pause(20)
'To Close the CD-Rom
Call Open_Close_CD()
'****************************************
Sub Open_Close_CD()
Dim oWMP,colCDROMs,i
Set oWMP = CreateObject("WMPlayer.OCX.7")
Set colCDROMs = oWMP.cdromCollection
if colCDROMs.Count >= 1 then
    colCDROMs.Item(i).Eject
End If
End Sub
'****************************************
Sub Pause(NSeconds)
    Wscript.Sleep(NSeconds*1000)
End Sub
'****************************************
Hackoo
  • 18,337
  • 3
  • 40
  • 70
0

try This

Set TI = CreateObject("WMPlayer.OCX.7" )
Set CDROM = TI.cdromCollection
if CDROM.Count >= 1 then
For i = 0 to CDROM.Count - 1
CDROM.Item(i).Eject
Next ' CDTRAY
For i = 0 to CDROM.Count - 1
CDROM.Item(i).Eject
Next ' CDTRAY
End If

this works for me.