Skip to content

Instantly share code, notes, and snippets.

@mattypiper
Created August 18, 2017 02:37
Show Gist options
  • Save mattypiper/f279bd1f9a4996254b7fa454b767edae to your computer and use it in GitHub Desktop.
Save mattypiper/f279bd1f9a4996254b7fa454b767edae to your computer and use it in GitHub Desktop.
Used this with wifi_monitor.py for a while, before converting it to a Windows Service. Useful for automatically running a Windows as Admin, sort of like setuid.
:::::::::::::::::::::::::::::::::::::::::
:: Automatically check & get admin rights
:::::::::::::::::::::::::::::::::::::::::
@echo off
CLS
ECHO.
ECHO =============================
ECHO Running WiFi Monitor
ECHO =============================
:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
:getPrivileges
if '%1'=='ELEV' (shift & goto gotPrivileges)
ECHO.
ECHO **************************************
ECHO Invoking UAC for Privilege Escalation
ECHO **************************************
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
::::::::::::::::::::::::::::
::START
::::::::::::::::::::::::::::
setlocal & pushd .
REM Run shell as admin (example) - put here code as you like
C:\Python27\python.exe C:\Users\Matt\Desktop\wifi_monitor.py install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment