@echo off
setlocal EnableExtensions
title IP Helper Service Setup

rem Request administrator privileges when the script is not elevated.
fltmc >nul 2>&1
if errorlevel 1 (
    call :say "0x5B,0x4FE1,0x606F,0x5D,0x20,0x6B63,0x5728,0x8BF7,0x6C42,0x7BA1,0x7406,0x5458,0x6743,0x9650,0x2E,0x2E,0x2E"
    powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath '%~f0' -WorkingDirectory '%~dp0' -Verb RunAs"
    exit /b 0
)

call :say "0x5B,0x31,0x2F,0x33,0x5D,0x20,0x6B63,0x5728,0x914D,0x7F6E,0x20,0x49,0x50,0x20,0x48,0x65,0x6C,0x70,0x65,0x72,0x20,0x670D,0x52A1,0x2E,0x2E,0x2E"
sc.exe config iphlpsvc start= auto
if errorlevel 1 goto :failed

call :say "0x5B,0x32,0x2F,0x33,0x5D,0x20,0x6B63,0x5728,0x542F,0x52A8,0x20,0x49,0x50,0x20,0x48,0x65,0x6C,0x70,0x65,0x72,0x20,0x670D,0x52A1,0x2E,0x2E,0x2E"
sc.exe start iphlpsvc >nul 2>&1

call :say "0x5B,0x33,0x2F,0x33,0x5D,0x20,0x6B63,0x5728,0x68C0,0x67E5,0x670D,0x52A1,0x72B6,0x6001,0x2E,0x2E,0x2E"
sc.exe query iphlpsvc
if errorlevel 1 goto :failed
set "SERVICE_STATE="
for /f "tokens=3" %%A in ('sc.exe query iphlpsvc ^| findstr /I "STATE"') do set "SERVICE_STATE=%%A"
if /I not "%SERVICE_STATE%"=="4" goto :failed

echo.
call :say "0x5B,0x6210,0x529F,0x5D,0x20,0x49,0x50,0x20,0x48,0x65,0x6C,0x70,0x65,0x72,0x20,0x5DF2,0x5F00,0x542F,0x5E76,0x6B63,0x5728,0x8FD0,0x884C,0x3002"
pause
exit /b 0

:failed
echo.
call :say "0x5B,0x5931,0x8D25,0x5D,0x20,0x49,0x50,0x20,0x48,0x65,0x6C,0x70,0x65,0x72,0x20,0x672A,0x8FD0,0x884C,0xFF0C,0x8BF7,0x68C0,0x67E5,0x4E0A,0x65B9,0x8F93,0x51FA,0x3002"
pause
exit /b 1

:say
powershell.exe -NoProfile -Command "[Console]::OutputEncoding=[Text.UTF8Encoding]::new($false); [Console]::WriteLine([string]::Concat([char[]](%~1)))"
exit /b 0
