I have a need to add my external IP address to the Windows registry on a scheduled basis, and I want to do this with a bat/cmd file to automate the process.
Now I just need a way to take that variable and inject it into the registry.
I know reg.exe or regedit.exe can add information to the registry by referencing a .REG file, but I don't quite know how to take the variable I get and add it without a .REG file.
One thing I already tried was using a .REG file already created, copying that to a new file (to preserve the original .REG file for reuse), then use echo to place the variable into the .REG file, like:
echo "some_reg_value"="%externalIP%" >> addIP.reg
The problem with this is the %externalIP% variable is adding an additional space after the IP address, so it looks like this in the .REG file and in the registry once the .REG file is added:
That extra space at the end causes a serious issue for the purpose I am trying to use it for.
Is there possibly a way to remove that extra space from the variable?
This is how I am getting the variable:
%CURL%\curl http://icanhazip.com > %CURL%\publicIP.txt for /f "delims= " %%G in (%CURL%\publicIP.txt) do set PublicIP=%%G & del %CURL%\publicIP.txt
Any help would be greatly appreciated. It has been quite a while since I tried to do a whole lot with batch scripting and I can't remember a lot of the available commands.