Translate

19 November 2013

Windows BATCH - how to get optical drive letter (CD/DVD)

Windows Batch - Find optical drive (CD/DVD/BD)

This script lists all available optical drives available on system using WMIC and then using loop command saves last listed letter in to variable.

@Echo OFF
:: Script to find and set optical drive available on system

SETLOCAL ENABLEDELAYEDEXPANSION
SET "WMIC=WMIC path win32_logicaldisk where drivetype^=4 get caption"

FOR /F "usebackq delims=" %%i IN (`%WMIC% ^|findstr ":"`) DO SET OPT=%%i
SET OPTICAL_DRV=%OPT:~0,2%

ECHO %OPTICAL_DRV%

No comments:

Post a Comment