Skip to content

Instantly share code, notes, and snippets.

@iNaD
Created February 13, 2015 15:33
Show Gist options
  • Save iNaD/852bf3f58e0fdee4381f to your computer and use it in GitHub Desktop.
Save iNaD/852bf3f58e0fdee4381f to your computer and use it in GitHub Desktop.
[Windows] Add a new host to your hosts File
@echo off
echo Administrative permissions required. Detecting permissions...
net session >nul 2>&1
if %errorLevel% == 0 (
echo Success: Administrative permissions confirmed.
) else (
echo Failure: No administrative permissions.
exit /B
)
set NEWLINE=^& echo.
if "%~1" == "" (
echo Please specify a domain
exit /B
) else (
set DOMAIN=%1
)
if "%~2" == "" (
set HOST=127.0.0.1
) else (
set HOST=%2
)
echo Using %HOST% as host for domain %DOMAIN%
find /C /I "%DOMAIN%" %WINDIR%\system32\drivers\etc\hosts
if %ERRORLEVEL% NEQ 0 (
echo %NEWLINE%^%HOST% %DOMAIN%>>%WINDIR%\System32\drivers\etc\hosts
) else (
echo Domain %DOMAIN% already exists
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment