|
Answer» 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= However the content of %data% is ■MRun this at the the CONSOLE. The variable %mediatype% will have the value DVD Writer
Code: [Select]for /f "TOKENS=* skip=2" %i in ('wmic cdrom where "mediatype!=\"unknown\"" get mediatype') do echo %mediatype%
Good luck. 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.
OK, lets try Solution 2.0
The variable %mediatype% will have the value DVD Writer
Code: [Select]for /f "tokens=* skip=1" %i in ('wmic cdrom where "mediatype!=\"unknown\"" get mediatype') do if not defined mediatype set mediatype=%i
Good luck.
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>)
Code: [Select]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%" pauseThe variable %mediatype% will have the value "DVD Writer"
|