-
Notifications
You must be signed in to change notification settings - Fork 0
/
System_Optimiser.bat
83 lines (73 loc) · 3.39 KB
/
System_Optimiser.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
@ECHO OFF
::ELEVATION START
setlocal EnableDelayedExpansion
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto START ) else ( goto getPrivileges )
:getPrivileges
if '%1'=='ELEV' ( goto START )
set "batchPath=%~f0"
set "batchArgs=ELEV"
set "script=%0"
set script=%script:"=%
IF '%0'=='!script!' ( GOTO PathQuotesDone )
set "batchPath=""%batchPath%"""
:PathQuotesDone
:ArgLoop
IF '%1'=='' ( GOTO EndArgLoop ) else ( GOTO AddArg )
:AddArg
set "arg=%1"
set arg=%arg:"=%
IF '%1'=='!arg!' ( GOTO NoQuotes ) else ( set "batchArgs=!batchArgs! "%1"" )
:NoQuotes
set "batchArgs=!batchArgs! %1"
shift
GOTO ArgLoop
:EndArgLoop
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
ECHO UAC.ShellExecute "cmd", "/c ""!batchPath! !batchArgs!""", "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs"
"%temp%\OEgetPrivileges.vbs"
exit /B
:START
IF '%1'=='ELEV' ( shift /1 )
cd /d %~dp0
::ELEVATION END
::ACCEPT
:: Warning the user about closing and saving open files
echo Warning: Please ensure all open files are closed and saved before proceeding.
echo.
echo Warning: Running this script may result in loss of data. By proceeding, you agree that you have closed and saved all necessary files and take full responsibility for any potential data loss.
echo.
echo Notice: Please run the User-Optimiser on this computer system for maximum effectiveness once this script has completed.
echo.
:: Prompting the user to confirm if they want to proceed with cleanup
set /p continue=Do you accept the terms and conditions (Y/N):
:: Checking user input to decide whether to proceed with cleanup or not
if /i "%continue%"=="Y" (
:: Begin cleanup script
start /B /wait rundll32.exe pnpclean.dll,RunDLL_PnpClean /drivers/maxclean
start /B /wait dism /Online /Cleanup-Image /CheckHealth
start /B /wait sfc /scannow
start /B /wait dism /Online /Cleanup-Image /RestoreHealth
start /B /wait dism /online /Cleanup-Image /Startcomponentcleanup /resetbase
del /s /f /q %temp%\*.*
del /s /f /q %windir%\Temp\*.*
del /s /f /q %windir%\Prefetch\*.*
del /s /q %windir%\Logs\CBS\*.*
del /s /q %windir%\Logs\DISM\*.*
del /s /q %SystemRoot%\System32\winevt\Logs\*.*
del /s /q %SystemRoot%\Logs\SetupCleanupTask\*.*
del /s /q %SystemRoot%\Logs\waasmediccapsule\*.*
del /s /q %SystemRoot%\Logs\WindowsUpdate\*.*
net stop wuauserv
rmdir /s /q %windir%\softwaredistribution
rmdir /s /q %SystemRoot%\Panther
net start wuauserv
:: Ask user to cleanup disk
powershell -Command "Add-Type -AssemblyName PresentationFramework; [System.Windows.MessageBox]::Show('Disk Cleanup will launch. Please select all of the files that you would like to delete and click on OK.', 'Disk Cleanup', 'OK', 'Information')"
powershell -Command "Start-Process cleanmgr -Verb RunAs -Wait"
powershell -Command "Add-Type -AssemblyName PresentationFramework; [System.Windows.MessageBox]::Show('Your computer will now restart. I Recommend you run the User-Optimiser on this computer system after your system has finished restarting.', 'System Optimisation Complete', 'OK', 'Information')"
shutdown -t 0 -r
) else (
:: Informing the user that script is aborted
powershell -Command "Add-Type -AssemblyName PresentationFramework; [System.Windows.MessageBox]::Show('System Optimisation Aborted.', 'Warning', 'OK', 'Warning')"
)