@echo off
setlocal enabledelayedexpansion

:: ============================================================
::  Adobe telemetry/privacy domain block script
::  Blocks ONLY data-reporting domains. Does NOT touch
::  activation/licensing/verification servers.
::
::  Usage:
::    Double-click            = add blocks
::    script.bat /uninstall   = remove entries added by this script
:: ============================================================

:: Require admin privileges.
:: Use "if errorlevel 1" instead of "if %errorlevel% neq 0" to avoid
:: the "level is not recognized" error caused by variable expansion.
net session >nul 2>&1
if errorlevel 1 (
    echo Administrator privileges required. Re-launching elevated...
    set "ARG=%~1"
    if not defined ARG set "ARG="
    powershell -NoProfile -Command ^
        "$p='%~f0'; $a='%ARG%'; Start-Process -FilePath 'powershell.exe' -ArgumentList '-NoProfile -Command ^& { ^& $p $a; pause }' -Verb RunAs"
    echo.
    echo A UAC prompt should appear. Please click ^"Yes^".
    echo If UAC didn't show or was cancelled, right-click this script ^> ^"Run as administrator^".
    pause
    exit /b
)

set "HOSTS=%SystemRoot%\System32\drivers\etc\hosts"
set "TAG=# adobe-tel"

:: --- Data-collection / telemetry domains only ---
:: NOTE: inferred from domain naming. Adobe endpoints change over versions;
:: verify with GlassWire/Wireshark before adding or removing.
:: Removed (activation/licensing/cert): activate* / practivate / lm.licenses /
::   ereg* / wip3 / prod.adobegenuine / crl / ocsp / ts1 / ts2
set "DOMAINS=hlrcv.stage.adobe.com hl2rcv.stage.adobe.com hlrcv.stage6.adobe.com hl2rcv.stage6.adobe.com data.adobegc.com adobe.tt.omtrdc.net sc.omtrdc.net smetrics.adobe.com dpm.demdex.net demdex.net assets.adobedtm.com adobedtm.com crs.cr.adobe.com crashreporter.adobe.com geo2.adobe.com stats.adobe.com survey.adobe.com"

if /i "%~1"=="/uninstall" goto uninstall

echo ============================================
echo   Adobe telemetry domain block (privacy only)
echo ============================================
echo Target: %HOSTS%
echo.

:: Locale-independent timestamp (does not rely on %date% format)
for /f %%i in ('powershell -NoProfile -Command "Get-Date -Format yyyyMMdd_HHmmss"') do set "TS=%%i"
set "BAK=%HOSTS%.bak_%TS%"
copy /y "%HOSTS%" "%BAK%" >nul 2>&1
echo Backup: %BAK%
echo.

REM Ensure the hosts file ends with a newline before appending
echo.>>"%HOSTS%"

set /a COUNT=0
set /a SKIP=0

for %%D in (%DOMAINS%) do (
    findstr /c:"%%D" "%HOSTS%" >nul 2>&1
    if errorlevel 1 (
        >>"%HOSTS%" echo 127.0.0.1 %%D %TAG%
        set /a COUNT+=1
        echo [+] 127.0.0.1 %%D
    ) else (
        set /a SKIP+=1
        echo [.] %%D already present, skipped
    )
)

echo.
echo ============================================
echo   Done: added %COUNT%, skipped %SKIP%
echo ============================================
echo Backup: %BAK%
echo To restore: run  %~nx0 /uninstall  as administrator
echo.
pause
exit /b

:uninstall
echo ============================================
echo   Removing entries added by this script
echo ============================================
echo.

for /f %%i in ('powershell -NoProfile -Command "Get-Date -Format yyyyMMdd_HHmmss"') do set "TS=%%i"
set "BAK=%HOSTS%.bak_%TS%"
copy /y "%HOSTS%" "%BAK%" >nul 2>&1
echo Backup: %BAK%

findstr /v /c:"%TAG%" "%HOSTS%" > "%HOSTS%.tmp"
move /y "%HOSTS%.tmp" "%HOSTS%" >nul
echo Removed all entries tagged %TAG%.
echo.
pause
exit /b
