Last active
February 17, 2021 21:04
-
-
Save VickyDev986/c680cf6a33b7abe89b2514a1b17ef10f to your computer and use it in GitHub Desktop.
Disable Windows Updates & Cleanup Fetched / Downloaded files
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
:::::::::::::::::::::::::::::::::::::::::::: | |
:: Automatically check & get admin rights V2 | |
:::::::::::::::::::::::::::::::::::::::::::: | |
@echo off | |
CLS | |
ECHO. | |
ECHO ============================= | |
ECHO Running Admin shell | |
ECHO ============================= | |
:init | |
setlocal DisableDelayedExpansion | |
set "batchPath=%~0" && mkdir %temp% 2> NUL | |
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%" | |
ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%" | |
"%SystemRoot%\System32\WScript.exe" "%vbsGetPrivileges%" %* | |
exit /B | |
:gotPrivileges | |
setlocal & pushd . | |
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 | |
ECHO %batchName% Arguments: %1 %2 %3 %4 %5 %6 %7 %8 %9 | |
Net Stop bits & Net Stop wuauserv & Net Stop appidsvc & Net Stop cryptsvc & Net Stop msiserver | |
Set "Dir1=%WinDir%\Downloaded Program Files" && Call Del /f /s /q %%Dir1%%\* 2>nul && Call RmDir /s /q %%Dir1%% | |
Set "Dir2=%WinDir%\SoftwareDistribution\Download" && Call Del /f /s /q %%Dir2%%\* 2>nul && Call RmDir /s /q %%Dir2%% | |
Set "Dir3=%WinDir%\SoftwareDistribution\DataStore" && Call Del /f /s /q %%Dir3%%\* 2>nul && Call RmDir /s /q %%Dir3%% | |
Exit /B 0 |
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
:::::::::::::::::::::::::::::::::::::::::::: | |
:: Automatically check & get admin rights V2 | |
:::::::::::::::::::::::::::::::::::::::::::: | |
@echo off | |
CLS | |
ECHO. | |
ECHO ============================= | |
ECHO Running Admin shell | |
ECHO ============================= | |
:init | |
setlocal DisableDelayedExpansion | |
set "batchPath=%~0" && mkdir %temp% 2> NUL | |
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%" | |
ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%" | |
"%SystemRoot%\System32\WScript.exe" "%vbsGetPrivileges%" %* | |
exit /B | |
:gotPrivileges | |
setlocal & pushd . | |
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 | |
ECHO %batchName% Arguments: %1 %2 %3 %4 %5 %6 %7 %8 %9 | |
Net Stop bits & Net Stop wuauserv & Net Stop appidsvc & Net Stop cryptsvc & Net Stop msiserver | |
Set "Dir1=%WinDir%\Downloaded Program Files" && Call Del /f /s /q %%Dir1%%\* 2>nul && Call RmDir /s /q %%Dir1%% | |
Set "Dir2=%WinDir%\SoftwareDistribution\Download" && Call Del /f /s /q %%Dir2%%\* 2>nul && Call RmDir /s /q %%Dir2%% | |
Set "Dir3=%WinDir%\SoftwareDistribution\DataStore" && Call Del /f /s /q %%Dir3%%\* 2>nul && Call RmDir /s /q %%Dir3%% | |
Exit /B 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment