Batch: Add New Registry Key Remotely

Batch: Add New Registry Key Remotely

As a systems administrator sometimes I find myself in a situation where I need to make a registry change across a few computers, or even a few hundred. I was googleing for a while this week trying to figure this out and saw some very complex solutions, but found a few sites to include TechNet that lead me into this much simpler solution:

@echo off
FOR /f %%F IN (feedme.txt) DO (
REG ADD \\%%F\HKLM\SYSTEM\example\example /v TestValue /t REG_DWORD /d 0
echo %%F is done
)

Here is the breakdown of how this works

FOR /f %%F IN (feedme.txt) DO (

The above is a for loop that for every line of the “feedme.txt” it will perform (DO) a specific action(s). feedme.txt should contain computer names or IP addresses.

REG ADD \\%%F\HKLM\SYSTEM\example\example /v TestValue /t REG_DWORD /d 0

REG ADD will add a registry key to the \\%%F (Computer Name from the list) \path within the registry /v (Value) /t (Type) /d (data)

echo %%F is done

This line simply tells you its done with that machine, it doesn’t always mean it was successful, but it is useful to see where you stand if you feed the script a huge list.

)

Closes the loop.

Comments are closed.