Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch Command Line to Eject CD Tray?

I'm currently trying to move my CD's of backup to my Backup HDD.

To automate the task I'm trying to create a batch to copy the files with the label of the CD than eject the media.

The code looks like this so far:

@echo off 
SET dest=F:\Backup\

d:

:: routine to retrieve volume label.
for /f "tokens=1-5*" %%1 in ('vol') do (
   set vol=%%6 & goto done
)
:done

:: create destination folder
set dest=%dest%%vol%
mkdir "%dest%"

:: copy to destiny folder
xcopy "d:" "%dest%" /i /s /exclude:c:\excludes.txt

::eject CD



c:

I'm stuck at eject part. I'm trying to eject the CD because I want a clear line to draw my attention when the copy finished (I thought opening the tray to be a good one).

Any ideas how to do it using Batch? Or any other ways to "draw the attention" to the end of the copy event?

Thanks :)

like image 501
Fawix Avatar asked Oct 19 '13 15:10

Fawix


1 Answers

if you have no installed media player or anti virus alarms check my other answer.

:sub echo(str) :end sub
echo off
'>nul 2>&1|| copy /Y %windir%\System32\doskey.exe '.exe >nul

'& cls
'& cscript /nologo /E:vbscript %~f0
'& pause




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

This is a batch/vbscript hybrid (you need to save it as a batch) .I don't think is possible to do this with simple batch.On windows 8/8.1 might require download of windows media player (the most right column).Some anti-virus programs could warn you about this script.

like image 124
npocmaka Avatar answered Sep 23 '22 00:09

npocmaka