Added windows_updates.py
This commit is contained in:
parent
ceb3fc4835
commit
990037e6c1
1 changed files with 58 additions and 0 deletions
58
.bin/Scripts/functions/windows_updates.py
Normal file
58
.bin/Scripts/functions/windows_updates.py
Normal file
|
|
@ -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
|
||||||
Loading…
Reference in a new issue