Find CD-ROM drive letter from with MS-DOS commanf file

G

Guest

I need to be able to find out which drive letter the CD-ROM/DVD drive is on
on any PC whilst a DOS command file is running. Is there a parameter I can
use that will return it? If necessary I could prompt for it. But my Users
may not know the answer. So I wouild prefer not to use this approach - bu
how do I handle the case where there could be multiple optical drives
installed?
 
T

Torgeir Bakken \(MVP\)

Brian said:
I need to be able to find out which drive letter the CD-ROM/DVD drive is on
on any PC whilst a DOS command file is running. Is there a parameter I can
use that will return it? If necessary I could prompt for it. But my Users
may not know the answer. So I wouild prefer not to use this approach - bu
how do I handle the case where there could be multiple optical drives
installed?
Hi

If several CD-ROM/DVD drives are available on a computer, the scripts
below will return the last CD drive.


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