diff --git a/scripts/auto_repairs.py b/scripts/auto_repairs.py index 7b816e6d..2de242ec 100644 --- a/scripts/auto_repairs.py +++ b/scripts/auto_repairs.py @@ -42,6 +42,8 @@ BASE_MENUS = { MenuEntry('Create System Restore', 'auto_system_restore_create'), MenuEntry('Backup Browsers', 'auto_backup_browser_profiles'), MenuEntry('Backup Power Plans', 'auto_backup_power_plans'), + MenuEntry('Reset Power Plans', 'auto_reset_power_plans'), + MenuEntry('Set Custom Power Plan', 'auto_set_custom_power_plan'), MenuEntry('Backup Registry', 'auto_backup_registry'), ), 'Windows Repairs': ( @@ -64,6 +66,7 @@ BASE_MENUS = { MenuEntry('KVRT', 'auto_kvrt'), MenuEntry('EmsisoftCmd', 'auto_emsisoft_cmd'), MenuEntry('Windows Defender', 'auto_microsoft_defender'), + MenuEntry('Remove Custom Power Plan', 'auto_remove_power_plan'), MenuEntry('Reboot', 'auto_reboot'), ), 'Manual Steps': ( diff --git a/scripts/wk/repairs/win.py b/scripts/wk/repairs/win.py index a5c648f9..ca6465d8 100644 --- a/scripts/wk/repairs/win.py +++ b/scripts/wk/repairs/win.py @@ -121,6 +121,11 @@ MBAM_UNINSTALL_KEY = ( r'\{35065F43-4BB2-439A-BFF7-0F1014F2E0CD}_is1' ) OS_VERSION = float(platform.win32_ver()[0]) +POWER_PLANS = { + 'Balanced': '381b4222-f694-41f0-9685-ff5bb260df2e', + 'Custom': '01189998-8199-9119-725c-ccccccccccc3', + 'High Performance': '8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c', + } REG_UAC_DEFAULT_SETTINGS = { 'HKLM': { r'Software\Microsoft\Windows\CurrentVersion\Policies\System': ( @@ -766,6 +771,14 @@ def auto_reboot(group, name): reboot(30) +def auto_remove_power_plan(group, name): + """Remove custom power plan and set to Balanced.""" + result = TRY_PRINT.run( + 'Remove Custom Power Plan...', remove_custom_power_plan, + ) + save_settings(group, name, result=result) + + def auto_repair_registry(group, name): """Delete registry keys with embedded null characters.""" result = TRY_PRINT.run( @@ -774,6 +787,12 @@ def auto_repair_registry(group, name): save_settings(group, name, result=result) +def auto_reset_power_plans(group, name): + """Reset power plans.""" + result = TRY_PRINT.run('Reset Power Plans...', reset_power_plans) + save_settings(group, name, result=result) + + def auto_reset_proxy(group, name): """Reset proxy settings.""" result = TRY_PRINT.run('Clearing proxy settings...', reset_proxy) @@ -794,6 +813,12 @@ def auto_restore_uac_defaults(group, name): save_settings(group, name, result=result) +def auto_set_custom_power_plan(group, name): + """Set to a custom power plan.""" + result = TRY_PRINT.run('Set Custom Power Plan...', create_custom_power_plan) + save_settings(group, name, result=result) + + def auto_sfc(group, name): """Run SFC repairs.""" result = TRY_PRINT.run('SFC Scan...', run_sfc_scan) @@ -1221,6 +1246,38 @@ def update_emsisoft_cmd(): # OS Built-in Functions +def create_custom_power_plan(): + """Create new power plan and set as active.""" + custom_guid = POWER_PLANS['Custom'] + + # Duplicate High Performance plan + cmd = [ + 'powercfg', '-DuplicateScheme', + POWER_PLANS['High Performance'], custom_guid, + ] + run_program(cmd) + + # Change the name + cmd = ['powercfg', '-ChangeName', custom_guid, KIT_NAME_FULL] + run_program(cmd) + + # Set as active plan + cmd = ['powercfg', '-SetActive', custom_guid] + run_program(cmd) + + # Keep the display on + for setting in ('monitor-timeout-ac', 'monitor-timeout-dc'): + cmd = ['powercfg', '-Change', setting, '0'] + run_program(cmd) + + # Set CPU min state + for arg in ('-SetacValueIndex', '-SetdcValueIndex'): + cmd = [ + 'powercfg', arg, custom_guid, 'SUB_PROCESSOR', 'PROCTHROTTLEMIN', '5', + ] + run_program(cmd) + + def create_system_restore_point(): """Create System Restore point.""" cmd = [ @@ -1296,6 +1353,39 @@ def reboot(timeout=10): raise SystemExit +def remove_custom_power_plan(high_performance=False): + """Remove custom power plan and set to a built-in plan. + + If high_performance is True then set to High Performance and set + min CPU state to 5% otherwise set to Balanced with default settings. + """ + power_guid = POWER_PLANS['Balanced'] + if high_performance: + power_guid = POWER_PLANS['High Performance'] + + # Set active plan + cmd = ['powercfg', '-SetActive', power_guid] + run_program(cmd) + + # Delete custom power plan (if present) + cmd = ['powercfg', '-Delete', POWER_PLANS['Custom']] + run_program(cmd, check=False) + + # Set CPU min state (if needed) + if high_performance: + for arg in ('-SetacValueIndex', '-SetdcValueIndex'): + cmd = [ + 'powercfg', arg, power_guid, 'SUB_PROCESSOR', 'PROCTHROTTLEMIN', '5', + ] + run_program(cmd) + + +def reset_power_plans(): + """Reset power plans to their default settings.""" + cmd = ['powercfg', '-RestoreDefaultSchemes'] + run_program(cmd) + + def reset_proxy(): """Reset WinHTTP proxy settings.""" cmd = ['netsh', 'winhttp', 'reset', 'proxy']