From 990037e6c12f6f172465a9dae27d71cb3ce49538 Mon Sep 17 00:00:00 2001 From: 2Shirt <2xShirt@gmail.com> Date: Tue, 8 Jan 2019 20:53:32 -0700 Subject: [PATCH] Added windows_updates.py --- .bin/Scripts/functions/windows_updates.py | 58 +++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .bin/Scripts/functions/windows_updates.py diff --git a/.bin/Scripts/functions/windows_updates.py b/.bin/Scripts/functions/windows_updates.py new file mode 100644 index 00000000..07da565b --- /dev/null +++ b/.bin/Scripts/functions/windows_updates.py @@ -0,0 +1,58 @@ +# Wizard Kit: Functions - Windows updates + +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.""" + run_program(['sc', 'config', service_name, 'start=', 'disabled']) + + +def disable_windows_updates(): + """Disable windows updates and clear SoftwareDistribution folder.""" + # Stop Windows update service + stop_service('wuauserv') + disable_service('wuauserv') + + # Stop Background Intelligent Transfer Service + try: + stop_service('bits') + disable_service('bits') + except Exception: + # Going to ignore these errors + pass + + # Delete 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']) + + +def enable_windows_updates(): + """Enable windows updates""" + enable_service('bits') + enable_service('wuauserv') + + +def stop_service(service_name): + """Stop service.""" + run_program(['sc', 'stop', service_name]) + + +if __name__ == '__main__': + print("This file is not meant to be called directly.") + +# vim: sts=2 sw=2 ts=2