Batch file help. For loop not working...


  1. Posts : 10
    Windows 7 Professional 64-bit
       #1

    Batch file help. For loop not working...


    What im trying to accomplish:
    -I want to REG QUERY a registry entry that will output the value of a (*SpeedDuplex) string value
    -I then want to store that value in a variable

    The command im using and the output:
    REG QUERY "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007" /v *SpeedDuplex

    Output:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BF
    C1-08002BE10318}\0007
    *SpeedDuplex REG_SZ 0

    End of search: 1 match(es) found.


    My batch file looks like this:
    @echo off
    for /f "skip=2 tokens=3 delims= " %%R in ('REG QUERY "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007" /v *SpeedDuplex') do (
    set "reg_value=%%R"
    )
    echo %reg_value%


    Output of %reg_value%: which if you notice is the third word in the last line?
    Search:


    Tried changing the skip and tokens with no luck and im racking my brain because it looks correct to me. Anyway if anyone can point me in the right direction I would appreciate it. Thanks in advance and lets play some Destiny :)
      My Computer


  2. Posts : 1,049
    Windows 7 Pro 32
       #2

    The problem is that the last output is: End of search: 1 match(es) found.
    And the 3rd word there is search:

    If you try this instead:

    for /f "tokens=3" %%R in ('REG QUERY "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007" /v *SpeedDuplex ^| find "SpeedDuplex"') do (

    The last bold part will filter the output to only the line that displays SpeedDuplex. Then the 3rd word in the last line will be:

    *SpeedDuplex REG_SZ 0
      My Computer


  3. Posts : 10
    Windows 7 Professional 64-bit
    Thread Starter
       #3

    :D


    Tookeri said:
    The problem is that the last output is: End of search: 1 match(es) found.
    And the 3rd word there is search:

    If you try this instead:

    for /f "tokens=3" %%R in ('REG QUERY "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}\0007" /v *SpeedDuplex ^| find "SpeedDuplex"') do (

    The last bold part will filter the output to only the line that displays SpeedDuplex. Then the 3rd word in the last line will be:

    *SpeedDuplex REG_SZ 0

    That worked! Ill most def save that ^| find trick for the future. Thanks for taking the time to reply. Peace
      My Computer


  4. Posts : 1,049
    Windows 7 Pro 32
       #4

    You're welcome! And this might be good to know too:

    The ^ only works in a for loop. If you run it in a command prompt you have to skip that and only use | find "SpeedDuplex"
      My Computer


  5. Posts : 10
    Windows 7 Professional 64-bit
    Thread Starter
       #5

    Tookeri said:
    You're welcome! And this might be good to know too:

    The ^ only works in a for loop. If you run it in a command prompt you have to skip that and only use | find "SpeedDuplex"
    LOL! I figured that out since its the first thing I tried after it worked in the batch file. Thanks again.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 01:47.
Find Us