Skip to content

Commit

Permalink
2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
truelockmc committed Nov 20, 2024
1 parent 4769c5d commit 0cddb17
Showing 1 changed file with 111 additions and 0 deletions.
111 changes: 111 additions & 0 deletions PCOptimus.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import logging
import zipfile
import requests
import winreg
import win32com.client

# Logging-Konfiguration
Expand Down Expand Up @@ -373,6 +374,7 @@ def show_clean_menu():
rm_bloatware_button.pack(pady=10)
rm_dupe_button.pack(pady=10)
clean_mngr_button.pack(pady=10)
clean_startup_button.pack(pady=10)
wsreset_button.pack(pady=10)
disk_cleanup_button.pack(pady=10)
temp_cleanup_button.pack(pady=10)
Expand Down Expand Up @@ -743,7 +745,114 @@ def rm_dupe():
delete_btn.pack(pady=10)

search_duplicates(duplicate_window, result_listbox, delete_btn)

# Liste der kritischen Dateien/Ordner, die nicht deaktiviert werden sollen
critical_files = ["desktop.ini", "ntuser.dat", "pagefile.sys", "swapfile.sys"]
critical_dirs = ["system32", "SysWOW64"]

# Funktion, um Autostart-Programme aus Registry und Autostart-Ordner abzurufen
def get_autostart_programs():
autostart_programs = []
# Registry-Einträge hinzufügen
for key, (hive, path) in reg_paths.items():
try:
reg_key = winreg.OpenKey(hive, path)
i = 0
while True:
try:
name, value, _ = winreg.EnumValue(reg_key, i)
if not any(cf.lower() in value.lower() for cf in critical_files + critical_dirs):
autostart_programs.append({"name": name, "path": value, "source": key})
i += 1
except OSError:
break
winreg.CloseKey(reg_key)
logging.info(f"Startup Apps loaded from {path}")
except Exception as e:
logging.error(f"Error while trying to access {path}: {e}")

# Autostart-Ordner
startup_folder = os.path.expanduser("~\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup")
if os.path.exists(startup_folder):
for item in os.listdir(startup_folder):
item_path = os.path.join(startup_folder, item)
if os.path.isfile(item_path) and not any(cf.lower() in item.lower() for cf in critical_files):
autostart_programs.append({"name": item, "path": item_path, "source": "Startup Folder"})
logging.info("Gathered Startup Folder Apps")

return autostart_programs

# Globale Definition von reg_paths
reg_paths = {
"HKCU_Run": (winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Run"),
"HKCU_RunOnce": (winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\RunOnce"),
"HKLM_Run": (winreg.HKEY_LOCAL_MACHINE, r"Software\Microsoft\Windows\CurrentVersion\Run"),
"HKLM_RunOnce": (winreg.HKEY_LOCAL_MACHINE, r"Software\Microsoft\Windows\CurrentVersion\RunOnce")
}

# Funktion zum Deaktivieren ausgewählter Autostart-Programme
def disable_selected_autostart(selected_programs):
for program in selected_programs:
try:
if program["source"] == "Startup Folder":
os.remove(program["path"])
else:
hive, path = reg_paths[program["source"]]
reg_key = winreg.OpenKey(hive, path, 0, winreg.KEY_SET_VALUE)
winreg.DeleteValue(reg_key, program["name"])
winreg.CloseKey(reg_key)
logging.info(f"Deactivated: {program['name']} - {program['path']}")
except Exception as e:
messagebox.showerror("Error", f"An error occurred while deactivating startup for {program['name']}: {e}")
logging.error(f"Error while deactivating {program['name']}: {e}")


# Funktion, die beim Drücken des "Clean Startup"-Buttons ausgeführt wird
def clean_startup():
if not is_admin():
logging.info("Asking for right elevation.")
elevate()
else:
logging.info("Admin already achieved")
show_autostart_gui()

# GUI-Funktion zur Auswahl der Autostart-Programme
def show_autostart_gui():
programs = get_autostart_programs()
if not programs:
messagebox.showinfo("No Startup Apps", "No startup apps found")
logging.info("No startup apps found")
return

# Neues Fenster für die Auswahl der Autostart-Programme
window = tk.Toplevel(root)
window.title("Startup App Manager")
window.configure(bg="#2e2e2e")

# Liste der Checkboxen für jedes Autostart-Programm
checkboxes = []
for program in programs:
var = tk.BooleanVar()
cb = tk.Checkbutton(window, text=f"{program['name']} ({program['source']}) - {program['path']}", variable=var,
bg="#2e2e2e", fg="white", selectcolor="#444", activebackground="#555", activeforeground="white")
cb.pack(anchor="w", padx=10, pady=2)
checkboxes.append((var, program))

# Button zum Deaktivieren der ausgewählten Programme
def disable_selected():
selected_programs = [program for var, program in checkboxes if var.get()]
if selected_programs:
disable_selected_autostart(selected_programs)
messagebox.showinfo("Startup App Deactivation", "Selected apps won't run on startup anymore.")
logging.info("Selected apps successfully deactivated")
window.destroy()
else:
messagebox.showwarning("Nothing selected", "Please select any app or close this window")
logging.warning("Nothing selected")

disable_button = tk.Button(window, text="Disable", command=disable_selected, bg="#444", fg="white",
activebackground="#555", activeforeground="white", borderwidth=1, relief="raised")
disable_button.pack(pady=10)
create_shortcut()

# Creating the GUI
Expand Down Expand Up @@ -811,6 +920,8 @@ def rm_dupe():

rm_bloatware_button = tk.Button(root, text="Remove Bloatware", command=rm_Bloatware, bg="#444", fg="white", activebackground="#555", activeforeground="white", borderwidth=1, relief="raised")

clean_startup_button = tk.Button(root, text="Clean Startup", command=clean_startup, bg="#444", fg="white", activebackground="#555", activeforeground="white", borderwidth=1, relief="raised")

show_main_menu()

root.mainloop()

0 comments on commit 0cddb17

Please sign in to comment.