Eject CD via Command Line in Windows 7

batch fileejectwindowswindows 7

I have been trying to eject the cd drive with the use of the cmd.
However, I am stumped. Searching on the internet, I only found this answer:

eject D: 

and a similiar answer

eject D: /I

Both of them do not work.

EDIT
Now people have found this answer on superuser,

Set oWMP = CreateObject("WMPlayer.OCX.7")
Set colCDROMs = oWMP.cdromCollection
colCDROMs.Item(0).Eject

However, I get an error:

colCDROMS.Item is not recognized as an internal or external command, operable program or batch file.

Best Answer

You can eject a cd with a batch file (this is part vbscript

@echo off
echo Set oWMP = CreateObject("WMPlayer.OCX.7")  >> %temp%\temp.vbs
echo Set colCDROMs = oWMP.cdromCollection       >> %temp%\temp.vbs
echo For i = 0 to colCDROMs.Count-1             >> %temp%\temp.vbs
echo colCDROMs.Item(i).Eject                    >> %temp%\temp.vbs
echo next                                       >> %temp%\temp.vbs
echo oWMP.close                                 >> %temp%\temp.vbs
%temp%\temp.vbs
timeout /t 1
del %temp%\temp.vbs

This is not my work, I found it in the stackoverflow community:

Post Link: Batch Command Line to Eject CD Tray?
Answer Author: Bruno
Date Answered: Feb 10, 2015

Related Question