Skip to content

Instantly share code, notes, and snippets.

@jcefoli
Last active August 29, 2015 14:03
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 jcefoli/3d0eaf3b3199690c8cf3 to your computer and use it in GitHub Desktop.
Save jcefoli/3d0eaf3b3199690c8cf3 to your computer and use it in GitHub Desktop.
Edits Hosts File in Notepad++ With Admin Elevation
@echo off
REM Note - this will not work if npp is already running without admin privledges
:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
:getPrivileges
if '%1'=='ELEV' (shift & goto gotPrivileges)
setlocal DisableDelayedExpansion
set "batchPath=%~0"
setlocal EnableDelayedExpansion
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
ECHO UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs"
"%temp%\OEgetPrivileges.vbs"
exit /B
:gotPrivileges
setlocal & pushd .
REM Run as admin
start notepad++ "C:\Windows\system32\drivers\etc\hosts"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment