Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- :: Check for administrative privileges
- net session >nul 2>&1
- if %errorLevel% neq 0 (
- echo This script requires administrator privileges. Please run as administrator.
- powershell -Command "Start-Process -FilePath '%~f0' -Verb RunAs"
- exit /b
- )
- set "HOSTS_FILE=%SystemRoot%\System32\drivers\etc\hosts"
- set "ENTRY=192.168.1.200 gpcl.local"
- :: Check if exact line already exists
- findstr /R /C:"^%ENTRY%$" "%HOSTS_FILE%" >nul
- if %errorLevel% equ 0 (
- echo Entry already exists in hosts file.
- ) else (
- echo Adding entry to hosts file...
- >>"%HOSTS_FILE%" echo.%ENTRY%
- echo Entry added.
- )
- pause
Advertisement
Add Comment
Please, Sign In to add comment