-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem_tweaks.py
More file actions
56 lines (41 loc) · 1.6 KB
/
system_tweaks.py
File metadata and controls
56 lines (41 loc) · 1.6 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
# tweaks/system_tweaks.py
from __future__ import annotations
import subprocess
import tempfile
import shutil
from pathlib import Path
def run_cmd(cmd: str) -> str:
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
output = (result.stdout or "") + ("\n" + result.stderr if result.stderr else "")
return output.strip() or f"Command executed. ExitCode={result.returncode}"
def disable_hibernation() -> str:
return run_cmd('powercfg -h off')
def enable_ultimate_performance() -> str:
cmds = [
'powercfg -duplicatescheme e9a42b02-d5df-448d-aa00-03f14749eb61',
'powercfg /setactive e9a42b02-d5df-448d-aa00-03f14749eb61',
]
return "\n\n".join(run_cmd(c) for c in cmds)
def clear_temp_files() -> str:
temp_dir = Path(tempfile.gettempdir())
deleted = 0
failed = 0
for item in temp_dir.iterdir():
try:
if item.is_file() or item.is_symlink():
item.unlink(missing_ok=True)
deleted += 1
elif item.is_dir():
shutil.rmtree(item, ignore_errors=True)
deleted += 1
except Exception:
failed += 1
return f"Temp cleanup completed.\nDeleted items: {deleted}\nFailed items: {failed}"
def create_restore_point() -> str:
cmd = (
'powershell -ExecutionPolicy Bypass -Command '
'"Checkpoint-Computer -Description \\"NetBootX Restore Point\\" -RestorePointType \\"MODIFY_SETTINGS\\""'
)
return run_cmd(cmd)
def run_sfc_scan() -> str:
return run_cmd('sfc /scannow')