Computer Hope
Microsoft => Microsoft DOS => Topic started by: newage on April 11, 2020, 01:30:02 AM
-
Hello!
I need to determine whether the DVD device in the computer is DVD Writer or DVD reader
I do it through wmic cdrom where mediatype!='unknown' get mediatype
It returns
MediaType
DVD Writer
However, how can I put "DVD Writer" into variable?
I tried
wmic cdrom where mediatype!='unknown' get mediatype > tmpFile.txt
set /p data=<tmpFile.txt
However the content of %data% is
■M
-
Run this at the the console. The variable %mediatype% will have the value DVD Writer
for /f "tokens=* skip=2" %i in ('wmic cdrom where "mediatype!=\"unknown\"" get mediatype') do @echo %mediatype%
Good luck. 8)
-
Please disregard the previous post. When I returned to check it out, it failed. Sorry for any inconvenience. If I find a fix I will post any updated version.
8)
-
OK, lets try Solution 2.0
The variable %mediatype% will have the value DVD Writer
for /f "tokens=* skip=1" %i in ('wmic cdrom where "mediatype!=\"unknown\"" get mediatype') do if not defined mediatype set mediatype=%i
Good luck. 8)
-
Hi ;)
This how to fix your problem with a batch file :
The output of WMIC is unicode !
The trailing <CR> can be removed by passing the value through another FOR /F loop.
This also removes the phantom "blank" line (actually a <CR>)
@echo off
set "mediatype="
@for /f "skip=1 delims=" %%a in ('wmic cdrom where "mediatype!=\"unknown\"" get mediatype') do (
@for /f "delims=" %%b in ("%%a") do if not defined mediatype set "mediatype=%%~nb"
)
echo MediaType is : "%mediatype%"
pause
The variable %mediatype% will have the value "DVD Writer"