By Request VBS Script To Eject And Then Close A CD-ROM Or DVD Drive Door

 

This By Request VBS Script is in response to an email request where I was asked the following: “I have a VB script to open my CD drive but I have to close it myself. Can you tell me what the command to close it is. All I can find is the eject command.”

 

Set objCdDrive = CreateObject("WMPlayer.OCX.7")

Set colCDROM = objCdDrive.cdromCollection

If colCDROM.Count >= 1 then

For i = 0 to colCDROM.Count - 1

colCDROM.Item(i).Eject

Next

End If

 

My reply was just loop it using and additional Next and I sent him back the script below.

 

Note: If the Drive door is already opened when you run this VBS script it will just close the door. On laptops the mechanics may not be the same as desktops and the drive door will only open since it cannot be pulled back in.

 

VBS Script:

 

Set objCdDrive = CreateObject("WMPlayer.OCX.7")

Set colCDROM = objCdDrive.cdromCollection

 

If colCDROM.Count >= 1 then

For i = 0 to colCDROM.Count - 1

colCDROM.Item(i).Eject

Next

 

For i = 0 to colCDROM.Count - 1

colCDROM.Item(i).Eject

Next

 

End If

 

 

Published Tuesday, December 22, 2009 8:52 AM by dhite
Filed under:

Comments

No Comments