-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwindows_cleaner.py
197 lines (158 loc) · 9.18 KB
/
windows_cleaner.py
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import os
import subprocess
import winreg
import shutil
import urllib.request
import zipfile
import wmi
# Set console window title
os.system("title Windows_Optimisation_Pack Cleaner | /u00A9 unofficialdxnny")
# Delete all shadow copies
subprocess.run(["vssadmin", "delete", "shadows", "/all", "/quiet"], stdout=subprocess.DEVNULL)
# Create system restore point
os.system("Checkpoint-Computer -Description 'Windows_Optimisation_Pack Cleaner' -RestorePointType MODIFY_SETTINGS")
# Modify registry keys to clean up disk space
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, "SOFTWARE/Microsoft/Windows/CurrentVersion/Explorer/VolumeCaches") as key:
for i in range(winreg.QueryInfoKey(key)[0]):
subkey_name = winreg.EnumKey(key, i)
if subkey_name == "DownloadsFolder":
continue
subkey_path = "SOFTWARE/Microsoft/Windows/CurrentVersion/Explorer/VolumeCaches//" + subkey_name
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, subkey_path, 0, winreg.KEY_WRITE) as subkey:
winreg.SetValueEx(subkey, "StateFlags0001", 0, winreg.REG_DWORD, 2)
# Flush DNS cache
os.system("ipconfig /flushdns")
# Run system file checker
os.system("sfc /SCANNOW")
# Analyze component store
os.system("Dism.exe /Online /Cleanup-Image /AnalyzeComponentStore")
# Remove superseded updates
os.system("Dism.exe /Online /Cleanup-Image /spsuperseded")
# Start component cleanup
os.system("Dism.exe /online /Cleanup-Image /StartComponentCleanup")
# Clear browser cache
os.system("Clear-BCCache -Force -ErrorAction SilentlyContinue")
# Remove temporary files
for path in [os.environ['temp'], os.environ['windir'] + '\\Temp']:
os.system(f"Get-ChildItem -Path {path} -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Recurse")
# Remove prefetch files
os.system("Get-ChildItem -Path $env:windir\\Prefetch -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Recurse")
# Remove software distribution files
os.system("Get-ChildItem -Path $env:SystemRoot\\SoftwareDistribution\\Download -Recurse -Force | Remove-Item -Recurse -Force")
# Remove retail demo files
os.system("Get-ChildItem -Path $env:ProgramData\\Microsoft\\Windows\\RetailDemo -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Recurse")
# Remove AMD files
for path in [os.environ['LOCALAPPDATA'] + '\\AMD', os.environ['windir'] + '\\..\\AMD']:
os.system(f"Get-ChildItem -Path {path} -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Recurse")
# Remove NVIDIA files
for path in [os.environ['LOCALAPPDATA'] + '\\NVIDIA\\DXCache', os.environ['LOCALAPPDATA'] + '\\NVIDIA\\GLCache']:
os.system(f"Get-ChildItem -Path {path} -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Recurse")
# Remove Intel files
os.system("Get-ChildItem -Path $env:APPDATA\\..\\locallow\\Intel\\ShaderCache -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Recurse")
# Remove crash dumps
os.system("Get-ChildItem -Path $env:LOCALAPPDATA\\CrashDumps -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Recurse")
# Remove AMD files (2)
os.system("Get-ChildItem -Path $env:APPDATA\\..\\locallow\\AMD -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Recurse")
# Remove Microsoft Office cache
os.system("Get-ChildItem -Path $env:windir\\..\\MSOCache")
# Remove Call of Duty shader cache
os.system(f"Get-ChildItem -Path {os.environ['ProgramFiles(x86)']}\\Steam\\steamapps\\common\\\"Call of Duty HQ\"\\shadercache -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Recurse")
def delete_folder(path):
try:
shutil.rmtree(path)
except FileNotFoundError:
pass
def main():
if winreg.QueryValueEx(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\EscapeFromTarkov"):
subprocess.call(["taskkill", "/F", "/IM", "EscapeFromTarkov.exe"])
escape_from_tarkov = winreg.QueryValueEx(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\EscapeFromTarkov", "InstallLocation")[0]
delete_folder(os.path.join(escape_from_tarkov, "Logs"))
delete_folder(os.path.join(os.environ["TEMP"], "Battlestate Games"))
if winreg.QueryValueEx(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 1938090"):
subprocess.call(["taskkill", "/F", "/IM", "cod.exe"])
call_of_duty_mw2_steam = winreg.QueryValueEx(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 1938090", "InstallLocation")[0]
delete_folder(os.path.join(call_of_duty_mw2_steam, "shadercache"))
if winreg.QueryValueEx(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Call of Duty"):
subprocess.call(["taskkill", "/F", "/IM", "cod.exe"])
call_of_duty_mw2_battlenet = winreg.QueryValueEx(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Call of Duty", "InstallLocation")[0]
delete_folder(os.path.join(call_of_duty_mw2_battlenet, "shadercache"))
subprocess.call(["lodctr", "/r"])
subprocess.call(["lodctr", "/r"])
os.system("cls")
print("Datentraeger Bereinigung wird gestartet...")
subprocess.call(["cleanmgr.exe", "/sagerun:1", "/d", "C:"], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
print("The System has been cleaned")
if __name__ == "__main__":
main()
hash = {}
ScriptFolder = os.path.join(os.environ['TEMP'], 'Windows_Optimisation_Pack')
try:
winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE\\Windows_Optimisation_Pack')
except:
pass
WindowsVersion = wmi.WMI().Win32_OperatingSystem()[0].Caption
InstalledSoftware = [item.DisplayName for item in winreg.QueryInfoKey(winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'))[0]]
if not os.path.exists(ScriptFolder):
os.mkdir(ScriptFolder)
def WindowsTweaks_Services():
subprocess.run(["Stop-Service", "WpcMonSvc"])
subprocess.run(["Stop-Service", "SharedRealitySvc"])
subprocess.run(["Stop-Service", "Fax"])
subprocess.run(["Stop-Service", "autotimesvc"])
subprocess.run(["Stop-Service", "wisvc"])
subprocess.run(["Stop-Service", "SDRSVC"])
subprocess.run(["Stop-Service", "MixedRealityOpenXRSvc"])
subprocess.run(["Stop-Service", "WalletService"])
subprocess.run(["Stop-Service", "SmsRouter"])
subprocess.run(["Stop-Service", "SharedAccess"])
subprocess.run(["Stop-Service", "MapsBroker"])
subprocess.run(["Stop-Service", "PhoneSvc"])
subprocess.run(["Stop-Service", "ScDeviceEnum"])
subprocess.run(["Stop-Service", "icssvc"])
subprocess.run(["Stop-Service", "edgeupdatem"])
subprocess.run(["Stop-Service", "edgeupdate"])
subprocess.run(["Stop-Service", "MicrosoftEdgeElevationService"])
subprocess.run(["Stop-Service", "RetailDemo"])
subprocess.run(["Stop-Service", "MessagingService"])
subprocess.run(["Stop-Service", "PimIndexMaintenanceSvc"])
subprocess.run(["Stop-Service", "OneSyncSvc"])
subprocess.run(["Stop-Service", "UnistoreSvc"])
subprocess.run(["Stop-Service", "DiagTrack"])
subprocess.run(["Stop-Service", "dmwappushservice"])
subprocess.run(["Stop-Service", "diagnosticshub.standardcollector.service"])
subprocess.run(["Stop-Service", "diagsvc"])
subprocess.run(["Stop-Service", "WerSvc"])
subprocess.run(["Stop-Service", "wercplsupport"])
subprocess.run(["Set-Service", "WpcMonSvc", "-StartupType", "Disabled"])
subprocess.run(["Set-Service", "SharedRealitySvc", "-StartupType", "Disabled"])
subprocess.run(["Set-Service", "Fax", "-StartupType", "Disabled"])
subprocess.run(["Set-Service", "autotimesvc", "-StartupType", "Disabled"])
subprocess.run(["Set-Service", "wisvc", "-StartupType", "Disabled"])
subprocess.run(["Set-Service", "SDRSVC", "-StartupType", "Disabled"])
subprocess.run(["Set-Service", "MixedRealityOpenXRSvc", "-StartupType", "Disabled"])
subprocess.run(["Set-Service", "WalletService", "-StartupType", "Disabled"])
subprocess.run(["Set-Service", "SmsRouter", "-StartupType", "Disabled"])
subprocess.run(["Set-Service", "SharedAccess", "-StartupType", "Disabled"])
subprocess.run(["Set-Service", "MapsBroker", "-StartupType", "Disabled"])
subprocess.run(["Set-Service", "PhoneSvc", "-StartupType", "Disabled"])
subprocess.run(["Set-Service", "ScDeviceEnum", "-StartupType", "Disabled"])
subprocess.run(["Set-Service", "TabletInputService", "-StartupType", "Disabled"])
subprocess.run(["Set-Service", "icssvc", "-StartupType", "Disabled"])
subprocess.run(["Set-Service", "edgeupdatem", "-StartupType", "Disabled"])
subprocess.run(["Set-Service", "edgeupdate", "-StartupType", "Disabled"])
subprocess.run(["Set-Service", "MicrosoftEdgeElevationService", "-StartupType", "Disabled"])
services = [
"RetailDemo",
"MessagingService",
"PimIndexMaintenanceSvc",
"OneSyncSvc",
"UnistoreSvc",
"DiagTrack",
"dmwappushservice",
"diagnosticshub.standardcollector.service",
"diagsvc",
"WerSvc",
"wercplsupport"
]
for service in services:
subprocess.run(["sc", "config", service, "start=", "disabled"])