Find Drive Letter for CD-ROM Drive in MS-DOS Batch File

G

Guest

I need to find out how to find out what the drive letter is for the CD-ROM on
any PC from within an MS-DOS batch command file. What is th ebest way of
doin it?
 
T

Torgeir Bakken \(MVP\)

Brian said:
I need to find out how to find out what the drive letter is for
the CD-ROM on any PC from within an MS-DOS batch command file.
What is the best way of doin it?
Hi

WinXP and Win2k3 Server only:

--------------------8<----------------------
@echo off
set cdrom=none
for %%a in (c d e f g h i j k l m n o p q r s t u v w x y z) do (
fsutil.exe fsinfo drivetype %%a:|find "CD-ROM">nul&&set cdrom=%%a:
)
echo CD-ROM drive letter: %cdrom%
--------------------8<----------------------


This batch file should work for all computers that have IE 5.01
or newer installed (so WSH/VBScript is available):

--------------------8<----------------------
@echo off
echo DL="none" >%tmp%\tmp.vbs
echo Set C = CreateObject("Scripting.FileSystemObject").Drives >>%tmp%\tmp.vbs
echo For Each D In C: If D.DriveType = 4 Then DL=D.DriveLetter >>%tmp%\tmp.vbs
echo Next >>%tmp%\tmp.vbs
echo WScript.Echo DL >>%tmp%\tmp.vbs
for /f "tokens=1" %%a in (
'cscript.exe //Nologo %tmp%\tmp.vbs') do set cdrom=%%a

del %tmp%\tmp.vbs
echo CD-ROM drive letter: %cdrom%:
--------------------8<----------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top