Skip to content

Instantly share code, notes, and snippets.

@lonekorean
Last active December 12, 2015 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lonekorean/4750532 to your computer and use it in GitHub Desktop.
Save lonekorean/4750532 to your computer and use it in GitHub Desktop.
Addhost v1.2 Windows batch script
@echo off
rem Addhost v1.2 by Will Boyd
set sitename=Default Web Site
set hostfilepath=%windir%\System32\drivers\etc\hosts
set appcmdpath=%windir%\system32\inetsrv\appcmd
echo Checking privileges...
net session >nul 2>&1
if not %ERRORLEVEL% == 0 (
echo This script must be run with administrator privileges.
goto end
)
set hostname=%1
if "%1"=="" (
set /p hostname="Enter the hostname to add (ex: dev.potato.com): "
)
echo Appending to hosts file...
echo.>>%hostfilepath%
echo 127.0.0.1 %hostname%>>%hostfilepath%
echo Adding binding...
%appcmdpath% set site /site.name:"%sitename%" /+bindings.[protocol='http',bindingInformation='*:80:%hostname%']>nul
echo Restarting site...
%appcmdpath% stop site /site.name:"%sitename%">nul
%appcmdpath% start site /site.name:"%sitename%">nul
echo Done. Go nuts!
:end
echo.
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment