Skip to content

Instantly share code, notes, and snippets.

@jcefoli
Last active Aug 29, 2015
Embed
What would you like to do?
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