Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::::::::::::::::::::::::::::::::::::::::::::
- :: Elevate.cmd - Version 4
- :: Automatically check & get admin rights
- :: see "https://stackoverflow.com/a/12264592/1016343" for description
- ::::::::::::::::::::::::::::::::::::::::::::
- @echo off
- CLS
- ECHO.
- ECHO =============================
- ECHO Running Admin shell
- ECHO =============================
- :init
- setlocal DisableDelayedExpansion
- set cmdInvoke=1
- set winSysFolder=System32
- set "batchPath=%~0"
- for %%k in (%0) do set batchName=%%~nk
- set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
- setlocal EnableDelayedExpansion
- :checkPrivileges
- NET FILE 1>NUL 2>NUL
- if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
- :getPrivileges
- if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
- ECHO.
- ECHO **************************************
- ECHO Invoking UAC for Privilege Escalation
- ECHO **************************************
- ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
- ECHO args = "ELEV " >> "%vbsGetPrivileges%"
- ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
- ECHO args = args ^& strArg ^& " " >> "%vbsGetPrivileges%"
- ECHO Next >> "%vbsGetPrivileges%"
- if '%cmdInvoke%'=='1' goto InvokeCmd
- ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
- goto ExecElevation
- :InvokeCmd
- ECHO args = "/c """ + "!batchPath!" + """ " + args >> "%vbsGetPrivileges%"
- ECHO UAC.ShellExecute "%SystemRoot%\%winSysFolder%\cmd.exe", args, "", "runas", 1 >> "%vbsGetPrivileges%"
- :ExecElevation
- "%SystemRoot%\%winSysFolder%\WScript.exe" "%vbsGetPrivileges%" %*
- exit /B
- :gotPrivileges
- setlocal & cd /d %~dp0
- if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul & shift /1)
- ::::::::::::::::::::::::::::
- ::START
- ::::::::::::::::::::::::::::
- REM Run shell as admin (example) - put here code as you like
- cd %userprofile%\Desktop
- rem get archive utility
- bitsadmin /transfer getingArchiveUtility /download /priority normal http://www.stahlworks.com/dev/unzip.exe %userprofile%\Desktop\unzip.exe
- rem get redshift application
- bitsadmin /transfer getingRedshiftApplication /download /priority normal https://github.com/jonls/redshift/releases/download/v1.12/redshift-windows-x86_64.zip %userprofile%\Desktop\redshift-windows-x86_64.zip
- rem unzip archive
- start /wait "" "%userprofile%\Desktop\unzip.exe" redshift-windows-x86_64.zip
- rem create turn on bat launcher
- (
- echo @echo off
- echo start "" "%userprofile%\Desktop\redshift-windows-x86_64\redshift.exe" -O 3700
- ) > "%userprofile%\Desktop\redshift-windows-x86_64\redshift_on.bat"
- rem create turn off bat launcher
- (
- echo @echo off
- echo start "" "%userprofile%\Desktop\redshift-windows-x86_64\redshift.exe" -x
- ) > "%userprofile%\Desktop\redshift-windows-x86_64\redshift_off.bat"
- rem add startup shortcut
- mklink "%systemdrive%\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\redshift.lnk" "%userprofile%\Desktop\redshift-windows-x86_64\redshift_on.bat"
- rem delete archiver
- del "%userprofile%\Desktop\unzip.exe"
- rem delete program's zip file
- del "%userprofile%\Desktop\redshift-windows-x86_64.zip"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement