Ejecting a CD or DVD drive from a command prompt

If you need to eject a CD/DVD disk drive from a command line interface (CLI) there are a number of ways to do so. Three ways to do so from a command prompt on a Microsoft Windows system are included below.

Batch File

@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

The batch file is from a response by Bruno to the Stack Overflow question Batch Command Line to Eject CD Tray?. The person who posted the answer notes:

just make sure you don't have a file called "temp.vbs" in your Temp folder. This can be executed directly through a cmd, you don't need a batch, but I don't know any command like "eject E:\". Remember that this will eject all CD trays in your system.

Batch file: ejectcdtray.bat

Wizmo

The script doesn't provide the capability to retract the drive platter. If you wish to close the drive, you can use the Wizmo utility from Steve Gibson of Gibson Research Corporation, which provides the capability to both open and close a CD or DVD drive in addition to providing many other capabilities. You can see the functions it performs by double-clicking on the wizmo.exe file or typing wizmo at a command prompt from the directory where the exe file is located, which will open a graphical user interface (GUI) window where the program's functions are listed. To open or close a CD/DVD drive from a command prompt, though, you can type wizmo open or wizmo close.

NirCmd

A third alternative is to use NirCmd from Nirs Sofer's NirSoft website. You can use nircmd cdrom open and nircmd cdrom close to open and close a drive. You can use a drive letter to specify a specific drive, if the system has multiple optical drives, e.g., nircmd.exe cdrom open j:.

 

TechRabbit ad 300x250 newegg.com

Justdeals Daily Electronics Deals1x1 px