How to detect DVD drive letter via BATCH file in MS WIndows 7?

7,281

I need to know that DVD could have assigned letter D or E

wmic will give you this information.

Example output:

F:\test>wmic logicaldisk get deviceid, drivetype
DeviceID  DriveType
C:        3
D:        5
E:        2
F:        3

Notes:

DriveType   Meaning
 1          No root directory
 2          Removable drive
 3          Local hard disk
 4          Network disk
 5          Compact disk
 6          RAM disk

The following batch file will output the drive letter of your DVD/CD drive (GetCD.cmd):

@echo off
setlocal
for /f "skip=1 tokens=1,2" %%i in ('wmic logicaldisk get caption^, drivetype') do (
  if [%%j]==[5] echo %%i
  )
endlocal

Example output:

F:\test>GetCD
D:

F:\test>

Further Reading

Notes:

Share:
7,281

Related videos on Youtube

felix0000
Author by

felix0000

Updated on September 18, 2022

Comments

  • felix0000
    felix0000 almost 2 years

    How to detect DVD drive letter via BATCH file in MS WIndows 7?

    I mean, I need to know that DVD could have assigned letter D or E...

    Is there any script to do it?

  • stevefestl
    stevefestl about 7 years
    If you used this code, then the batch file must be on the DVD or CD drive...