-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopti.py
More file actions
85 lines (69 loc) · 2.67 KB
/
opti.py
File metadata and controls
85 lines (69 loc) · 2.67 KB
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
import tkinter as tk
from tkinter import messagebox
import os
import shutil
import subprocess
import powerplan
root = tk.Tk()
root.withdraw()
binChoice = messagebox.askquestion("Bin", "Do you want to clear the recycle bin? (Recommended)")
if binChoice == "yes":
if os.path.isdir(r"C:\$Recycle.Bin") == True:
for filePath in os.listdir(r"C:\$Recycle.Bin"):
filePath2 = os.path.join(r"C:\$Recycle.Bin", filePath)
for i in os.listdir(filePath2):
fileInBin = os.path.join(filePath2, i)
os.remove(fileInBin)
def delTemp():
if os.path.isdir(r"C:\Windows\Temp"):
for fileName in os.listdir(r"C:\Windows\Temp"):
tempFilePath = os.path.join(r"C:\Windows\Temp", fileName)
if os.path.isdir(tempFilePath):
shutil.rmtree(tempFilePath)
else:
os.remove(tempFilePath)
def delPrefetch():
if os.path.isdir(r"C:\Windows\Prefetch"):
for fileName in os.listdir(r"C:\Windows\Prefetch"):
pfFilePath = os.path.join(r"C:\Windows\Prefetch", fileName)
if os.path.isdir(pfFilePath):
pass
else:
os.remove(pfFilePath)
def delUpdates():
if os.path.isdir(r"C:\Windows\SoftwareDistribution\Download"):
for fileName in os.listdir(r"C:\Windows\SoftwareDistribution\Download"):
updateFilePath = os.path.join(r"C:\Windows\SoftwareDistribution\Download", fileName)
if os.path.isdir(updateFilePath):
shutil.rmtree(updateFilePath)
else:
os.remove(updateFilePath)
def clearLogs():
logList = ["Application", "System", "Security"]
for i in logList:
subprocess.run(["wevtutil", "cl", i])
def delRecent():
for i in os.listdir():
recentPath = os.path.join(os.path.join(os.environ["USERPROFILE"], "Recent"), i)
if os.path.isdir(recentPath):
shutil.rmtree(recentPath)
else:
os.remove(recentPath)
def delShadow():
subprocess.run(["vssadmin", "delete", "shadows", r"/all"])
def flushDNS():
subprocess.run(["ipconfig", r"/flushdns"])
def disableStartup():
subprocess.run(["reg","delete", r"HKCU\Software\Microsoft\Windows\CurrentVersion\Run", r"/f"])
def changePowerPlan():
powerplan.change_current_scheme_to_high()
pfChoice = messagebox.askquestion("Prefetch", "Do you want to clear the prefetch files? (Recommended)")
if pfChoice == True:
delPrefetch()
delTemp()
delUpdates()
clearLogs()
disableStartup()
delShadow()
flushDNS()
changePowerPlan()