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
- An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
- for /f - Loop command against the results of another command.
- wmic - Windows Management Instrumentation Command. Example output:
Notes:
Related videos on Youtube
Author by
felix0000
Updated on September 18, 2022Comments
-
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 about 7 yearsIf you used this code, then the batch file must be on the DVD or CD drive...