diff --git a/.bin/Scripts/functions/windows_updates.py b/.bin/Scripts/functions/windows_updates.py index 2504fdfc..4257f066 100644 --- a/.bin/Scripts/functions/windows_updates.py +++ b/.bin/Scripts/functions/windows_updates.py @@ -3,13 +3,6 @@ from functions.common import * -# STATIC VARIABLES -UPDATE_FOLDERS = [ - r'{WINDIR}\SoftwareDistribution'.format(**global_vars['Env']), - r'{SYSTEMDRIVE}\$WINDOWS.~BT'.format(**global_vars['Env']), -] - - # Functions def disable_service(service_name): """Set service startup to disabled.""" @@ -18,27 +11,28 @@ def disable_service(service_name): def disable_windows_updates(): """Disable windows updates and clear SoftwareDistribution folder.""" - # Stop Windows update service - stop_service('wuauserv') - disable_service('wuauserv') + update_folders = [ + r'{WINDIR}\SoftwareDistribution'.format(**global_vars['Env']), + r'{SYSTEMDRIVE}\$WINDOWS.~BT'.format(**global_vars['Env']), + ] - # Stop Background Intelligent Transfer Service - try: - stop_service('bits') - disable_service('bits') - except Exception: - # Going to ignore these errors - pass + # Stop services + for service in ('wuauserv', 'bits'): + stop_service(service) + disable_service(service) # Delete update folders - for folder_path in UPDATE_FOLDERS: + for folder_path in update_folders: if os.path.exists(folder_path): shutil.rmtree(folder_path) def enable_service(service_name): """Set service startup to enabled.""" - run_program(['sc', 'config', service_name, 'start=', 'automatic']) + try: + run_program(['sc', 'config', service_name, 'start=', 'automatic']) + except subprocess.CalledProcessError: + run_program(['sc', 'config', service_name, 'start=', 'auto']) def enable_windows_updates(): @@ -49,7 +43,7 @@ def enable_windows_updates(): def stop_service(service_name): """Stop service.""" - run_program(['net', 'stop', service_name]) + run_program(['net', 'stop', service_name], check=False) if __name__ == '__main__':