Last active
August 29, 2015 14:03
-
-
Save jcefoli/3d0eaf3b3199690c8cf3 to your computer and use it in GitHub Desktop.
Edits Hosts File in Notepad++ With Admin Elevation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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