Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- CLS
- :::::::::
- ::This script is used to automatically obtain admin privileges to allow the script to be run without choosing "run as administrator"
- :::::::::
- :: checking for admin privileges by attempting NET FILE
- :checkPrivileges
- NET FILE 1>NUL 2>NUL
- :: if admin privileges are available, skip the rest of the admin script. If not, begin the escalation script.
- if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
- :getPrivileges
- if '%1'=='ELEV' (shift & goto gotPrivileges)
- ECHO.
- ECHO **************************************
- ECHO Attempting to escalate privileges
- ECHO **************************************
- setlocal DisableDelayedExpansion
- set "batchPath=%~0"
- setlocal EnableDelayedExpansion
- :: echoing code into a .vbs file located in the temp directory which will get us our admin privileges, then running it
- 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 .
- :::::::
- :: this is where the actual script kicks in
- :::::::
- :start
- :: title of the window
- title Ailuri Task Wrapper 1.12
- echo.
- ECHO =============================
- ECHO Running as admin
- ECHO =============================
- :: looking for the task in question and displaying its current state
- schtasks /QUERY /TN "Anti spindown"
- echo.
- echo What would you like to do?
- echo.
- :: using set /p to accept user input
- set /p batch=Enter "e" to enable, "d" to disable, "q" to quit, or "r" to refresh:
- if "%batch%" equ "e" (
- goto enable
- )
- if "%batch%" equ "d" (
- goto disable
- )
- if "%batch%" equ "q" (
- goto end
- )
- if "%batch%" equ "r" (
- cls
- goto start
- )
- :enable
- :: enabling the task in question, then waiting for 1 second to allow the task to start before restarting the script
- schtasks.exe /CHANGE /TN "Anti spindown" /ENABLE
- schtasks.exe /RUN /TN "Anti spindown"
- timeout /t 1 > NUL
- cls
- goto start
- :disable
- :: disables the task in question and restarts the script. No need to wait here
- schtasks.exe /CHANGE /TN "Anti spindown" /DISABLE
- cls
- goto start
- :end
Advertisement
Add Comment
Please, Sign In to add comment