Windows 7 DOS Batch File to Open and Close Remote Computers’ CD/DVD Tray

CDME.bat Windows 7 DOS Batch File to Open and Close Remote Computers##Q## CD/DVD Tray

Sometime I get bored at work.

So I wrote this DOS batch file (cdme.bat) to open/close the CD/DVD tray on other peoples computers on the network.  It will ask you for the HOSTNAME of the target computer, and how many times you want to open/close the drive tray.  FUN FUN FUN :>

Requires:

EjectMedia32.exe

EjectMedia64.exe

LoadMedia.exe (all written by Uwe Sieber)

Requires Admin rights to the target.

Assumes that target##Q##s c:\ drive has default admin share enabled: “c$” for file copy/cleanup.

PSexec or PSTOOLS needed on computer running the batch, not the target.

 

 

rem CDME.bat Written by Galen Wollenberg 2013

@echo off
set /p hostname= Enter Target Computer HOSTNAME:

echo.
set /p reps= Open/Close tray how many times?:
echo.
set /a times = “reps”

echo copying files…
@echo off
copy ejectmedia32.exe \\%hostname%\c$\windows\temp
copy ejectmedia64.exe \\%hostname%\c$\windows\temp
copy loadmedia.exe \\%hostname%\c$\windows\temp

:CheckOS
echo.
echo Checking %hostname% for bits…
IF EXIST “%PROGRAMFILES(X86)%” (set bit=64) ELSE (set bit=32)
echo.
echo %hostname% is %bit% bits…
echo.
echo %times% total Open/Close cycles requested…
echo.
echo %reps% cycles remaining…
echo.

:CheckOS

IF EXIST “%PROGRAMFILES(X86)%” (GOTO 64) ELSE (GOTO 32)

:32
IF “%reps%” == “0” GOTO END
psexec \\%hostame% c:\windows\temp\ejectmedia32.exe d
rem wait 2 seconds
ping 192.0.2.2 -n 1 -w 2000 > nul
psexec \\%hostname% c:\windows\temp\loadmedia.exe d:
rem wait 2 seconds
ping 192.0.2.2 -n 1 -w 2000 > nul
set /a reps = reps – 1
cls
echo %times% total Open/Close cycles requested…
echo.
echo Ok, %reps% cycles remaining…

GOTO 32

:64

IF “%reps%” == “0” GOTO END
psexec \\%hostname% c:\windows\temp\ejectmedia64.exe d
rem wait 2 seconds
ping 192.0.2.2 -n 1 -w 2000 > nul
psexec \\%hostname% c:\windows\temp\loadmedia.exe d:
rem wait 2 seconds
ping 192.0.2.2 -n 1 -w 2000 > nul
set /a reps = reps – 1
cls
echo %times% total Open/Close cycles requested…
echo.
echo Ok, %reps% cycles remaining…
GOTO 64

:END
echo deleting files…
@echo off
del \\%hostname%\c$\windows\temp\ejectmedia32.exe
del \\%hostname%\c$\windows\temp\ejectmedia64.exe
del \\%hostname%\c$\windows\temp\loadmedia.exe

echo.
echo All Done! CD Tray opened/closed %times% times on %hostname% !
echo.
pause

 

 

Have Something to Add About This?