How do I create a batch script creates certain registry entries in all subfolders

1

I was reading this on the web:

  1. Press Windows Key + R, type "regedit" in the box, then press enter.
  2. Go to this path: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces
  3. Repeat steps 4 and 5 for all folders under "Interfaces" (You can have from 1-100 folders, i had 14)
  4. Create two new registry keys called "TcpAckFrequency" and "TCPNoDelay" (Right click on an empty scace, go to "New" and select DWORD (32-bit) Value)

How do I create a batch script that goes through all the folders in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces and adds the two DWORD entries of "TcpAckFrequency" and "TCPNoDelay"?

I'm assuming the FOR command is used but I just don't know how to do it.

Edit: I'd also like to know the code needed to go through and delete all those keys from the folders.

Ice

Posted 2016-02-22T04:27:38.773

Reputation: 37

What did you actually try out to complete your request? – Smeerpijp – 2016-02-22T10:50:05.913

Answers

1

How do I create a batch script that:

goes through all the folders in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces and adds the two DWORD entries of TcpAckFrequency and TCPNoDelay?

I'd also like to know the code needed to go through and delete all those keys from the folders.

Warning:

  • The instructions below contain steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly.

  • Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs.

  • For more information see How to back up and restore the registry in Windows


Use the following batch file (test.cmd):

@echo off
setlocal
rem get the keys
for /f "usebackq" %%i in (`reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces`) do (
  rem add the values
  reg add %%i /v "TcpAckFrequency" /d "1" /t REG_DWORD
  reg add %%i /v "TCPNoDelay" /d "1" /t REG_DWORD
  )
rem get the keys
for /f "usebackq" %%i in (`reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\Interfaces`) do (
  rem delete the values
  echo delete %%i /v "TcpAckFrequency" /f
  echo delete %%i /v "TCPNoDelay" /f
  )
endlocal

Note:

  • Replace the 1 in /d "1" with whatever value is appropriate for your use case.

Further Reading

DavidPostill

Posted 2016-02-22T04:27:38.773

Reputation: 118 938