title: How query registry key, find a string and edit it?
body: <p>May be out of line here but I stumbled on a batch script here on Stack Overflow and it was just what I wanted to do. But it is a quit old post and I can't get it to work.</p>
  
  <p>Original post: <a href="https://stackoverflow.com/questions/12521173/">Batch to query registry key, find a string within that key, then create a new key</a></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>I executed this batch file on Windows 10 Home Edition and it has not changed anything in Windows registry although running it as administrator.</p>
  
  <p>Can someone please help me to get this script to work?</p>
  
  <p>Result of reg query:</p>
  
  <pre><code>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0000
      DriverDesc    REG_SZ    Microsoft Kernel Debug Network Adapter
  
  HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0001
      DriverDesc    REG_SZ    Intel(R) Ethernet Connection I217-V
  
  HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0002
      DriverDesc    REG_SZ    Qualcomm Atheros AR946x Wireless Network Adapter
  
  HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0003
      DriverDesc    REG_SZ    Broadcom 802.11ac Network Adapter
  
  HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0004
      DriverDesc    REG_SZ    Bluetooth Device (RFCOMM Protocol TDI)
  
  HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\0005
      DriverDesc    REG_SZ    Microsoft Wi-Fi Direct Virtual Adapter
  </code></pre>