Last active
December 22, 2018 12:38
-
-
Save derari/bea27988418f18647e86b0ee5e536b29 to your computer and use it in GitHub Desktop.
This file contains 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 | |
CLS | |
ECHO. | |
ECHO ************************************** | |
ECHO Starting Chocolatey Batch | |
ECHO ************************************** | |
::::::::::::::::::::::::::::::::::::::::: | |
:: Automatically check & get admin rights | |
::::::::::::::::::::::::::::::::::::::::: | |
: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 . | |
WHERE choco 1>NUL 2>NUL | |
if '%errorlevel%' == '0' ( goto chocoInstalled ) else ( goto chocoMissing ) | |
:chocoMissing | |
ECHO. | |
choice /M "Chocolatey not found. Install now?" | |
IF '%errorlevel%' == '2' exit /B | |
ECHO. | |
ECHO ************************************** | |
ECHO Installing Chocolatey | |
ECHO ************************************** | |
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin | |
ECHO. | |
ECHO ************************************** | |
ECHO Installing Upgrade Task | |
ECHO ************************************** | |
ECHO ^<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"^> > "%temp%\chocotask.xml" | |
ECHO ^<Triggers^>^<CalendarTrigger^> >> "%temp%\chocotask.xml" | |
ECHO ^<StartBoundary^>2017-01-01T00:00:00^</StartBoundary^>^<Enabled^>true^</Enabled^>^<RandomDelay^>PT1M^</RandomDelay^> >> "%temp%\chocotask.xml" | |
ECHO ^<ScheduleByWeek^>^<DaysOfWeek^>^<Saturday /^>^</DaysOfWeek^>^<WeeksInterval^>1^</WeeksInterval^>^</ScheduleByWeek^> >> "%temp%\chocotask.xml" | |
ECHO ^</CalendarTrigger^>^</Triggers^> >> "%temp%\chocotask.xml" | |
ECHO ^<Settings^> >> "%temp%\chocotask.xml" | |
ECHO ^<DisallowStartIfOnBatteries^>true^</DisallowStartIfOnBatteries^> >> "%temp%\chocotask.xml" | |
ECHO ^<StartWhenAvailable^>true^</StartWhenAvailable^> >> "%temp%\chocotask.xml" | |
ECHO ^<RunOnlyIfNetworkAvailable^>true^</RunOnlyIfNetworkAvailable^> >> "%temp%\chocotask.xml" | |
ECHO ^</Settings^> >> "%temp%\chocotask.xml" | |
ECHO ^<Actions Context="Author"^> >> "%temp%\chocotask.xml" | |
ECHO ^<Exec^>^<Command^>choco^</Command^>^<Arguments^>upgrade all -y^</Arguments^>^</Exec^> >> "%temp%\chocotask.xml" | |
ECHO ^</Actions^> >> "%temp%\chocotask.xml" | |
ECHO ^</Task^> >> "%temp%\chocotask.xml" | |
more "%temp%\chocotask.xml" | |
schtasks /Create /TN choco-upgrade /F /IT /XML "%temp%\chocotask.xml" | |
schtasks /Change /TN choco-upgrade /RL HIGHEST | |
:chocoInstalled | |
ECHO. | |
ECHO ************************************** | |
ECHO Upgrading and Installing Packages | |
ECHO ************************************** | |
@echo on | |
choco feature enable --name=allowGlobalConfirmation | |
:: first, upgrade existing packages | |
choco upgrade all -y | |
set choco_install=choco install | |
:: Small Tools ::::::::::::: | |
%choco_install% ^ | |
putty.portable ^ | |
paint.net ^ | |
notepadplusplus ^ | |
winscp ^ | |
7zip ^ | |
sysinternals | |
: run "elevate -k choco install -y <package>" from non-admin cmd to install more packages | |
%choco_install% ^ | |
elevate.native | |
:: add more software here | |
pause | |
choco feature disable --name=allowGlobalConfirmation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment