title: Batch to query registry key, find a string within that key, then create a new key
body: <p>I'm looking to create a batch file that will perform a pretty specific function:</p>
  
  <p>Search the registry key "\HKLM\SYSTEM\CurrentControlSet\Control\Class{4D36E972-E325-11CE-BFC1-08002bE10318}"  </p>
  
  <p>Find all subkeys that contain a specific text string, in this case "Intel" in "DriverDesc" value  </p>
  
  <p>Change the "PnPCapabilities" value data to "38" (hex) only in the keys that contain "Intel" in "DriverDesc" value</p>
  
  <p>I know how to do each of these things separately, but I'm not quite able to get them all to work together in a single batch. My knowledge of the batch language is still too limited to know how to do it properly on my own, or to decipher and modify an existing batch.</p>
  
  <p>To make things less confusing, I'm trying to disable the power management options for a pair of Intel NIC cards. I'd like to make a batch that will automatically do this on any machine, regardless of what other NICs are present, or in which order they were installed.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>The following is what I've found, tried and failed:<br>
  <strong>EDIT:</strong> New batch<br>
  <strong>EDIT2:</strong> New batch, working </p>
  
  <pre><code>:start
  setlocal ENABLEDELAYEDEXPANSION
  set qry=reg query "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}" /s /v DriverDesc
  for /f "Tokens=*" %%p in ('%qry%') do (
   set var=%%p
   set var=!var:^&amp;=!
   set var=!var:^)=!
   set var=!var:^(=!
   call :parse
  )
  endlocal
  goto :EOF
  :parse
  if /i "%var:~0,5%" NEQ "HKEY_" goto parse1
  set key=%var%
  set key=%key:HKEY_LOCAL_MACHINE=HKLM%
  goto :EOF
  :parse1
  setlocal ENABLEEXTENSIONS
  for /f "Tokens=*" %%f in ('@echo %var%^|findstr /i /c:"Intel(R)"') do (
    if defined key reg add %key% /v PnPCapabilities /t REG_DWORD /d 56 /f&amp;set key=
  )
  endlocal &gt;nul 2&gt;&amp;1
  </code></pre>
  
  <p>Fixed so that it does what is intended.</p>