WizardKit/.bin/Scripts/functions/windows_updates.py

52 lines
1.3 KiB
Python

# Wizard Kit: Functions - Windows updates
from functions.common import *
# 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."""
update_folders = [
r'{WINDIR}\SoftwareDistribution'.format(**global_vars['Env']),
r'{SYSTEMDRIVE}\$WINDOWS.~BT'.format(**global_vars['Env']),
]
# Stop services
for service in ('wuauserv', 'bits'):
stop_service(service)
disable_service(service)
# 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."""
try:
run_program(['sc', 'config', service_name, 'start=', 'automatic'])
except subprocess.CalledProcessError:
run_program(['sc', 'config', service_name, 'start=', 'auto'])
def enable_windows_updates():
"""Enable windows updates"""
enable_service('bits')
enable_service('wuauserv')
def stop_service(service_name):
"""Stop service."""
run_program(['net', 'stop', service_name], check=False)
if __name__ == '__main__':
print("This file is not meant to be called directly.")
# vim: sts=2 sw=2 ts=2