58 lines
1.3 KiB
Python
58 lines
1.3 KiB
Python
# 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(['net', 'stop', service_name])
|
|
|
|
|
|
if __name__ == '__main__':
|
|
print("This file is not meant to be called directly.")
|
|
|
|
# vim: sts=2 sw=2 ts=2
|