Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How can I get the DVD device type into variable  (Read 115509 times)

0 Members and 1 Guest are viewing this topic.

newage

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Windows 7
    How can I get the DVD device type into variable
    « 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

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: How can I get the DVD device type into variable
    « Reply #1 on: April 11, 2020, 10:23:29 AM »
    Run 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.  8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: How can I get the DVD device type into variable
    « Reply #2 on: April 11, 2020, 11:37:24 AM »
    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)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: How can I get the DVD device type into variable
    « Reply #3 on: April 11, 2020, 01:44:30 PM »
    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.  8)


    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    Hackoo



      Hopeful
    • Thanked: 42
    • Experience: Expert
    • OS: Windows 10
    Re: How can I get the DVD device type into variable
    « Reply #4 on: April 11, 2020, 04:36:20 PM »
    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%"
    pause
    The variable %mediatype% will have the value "DVD Writer"