Old post, but converted to batch to run on a scheduled task. Since this writes to HKCU it does not need admin rights. Just have to setup LS to scan the reg key value.
@echo off
setlocal
:: Get public IP using curl
for /f "delims=" %%i in ('curl -s https://api.ipify.org') do set publicIP=%%i
:: Registry path (HKCU for current user, no admin needed)
set regPath=HKCU\SOFTWARE\COMPANYNAME\NetworkInfo
:: Create the registry key if it doesn't exist
reg query "%regPath%" >nul 2>&1
if errorlevel 1 (
reg add "%regPath%" /f >nul
)
:: Store the public IP in the registry
reg add "%regPath%" /v PublicIP /t REG_SZ /d %publicIP% /f >nul
endlocal
Seems to work as expected for us.