Updated windows_updates.py
This commit is contained in:
parent
af46962fd7
commit
d8e28ce785
1 changed files with 14 additions and 20 deletions
|
|
@ -3,13 +3,6 @@
|
||||||
from functions.common import *
|
from functions.common import *
|
||||||
|
|
||||||
|
|
||||||
# STATIC VARIABLES
|
|
||||||
UPDATE_FOLDERS = [
|
|
||||||
r'{WINDIR}\SoftwareDistribution'.format(**global_vars['Env']),
|
|
||||||
r'{SYSTEMDRIVE}\$WINDOWS.~BT'.format(**global_vars['Env']),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
# Functions
|
# Functions
|
||||||
def disable_service(service_name):
|
def disable_service(service_name):
|
||||||
"""Set service startup to disabled."""
|
"""Set service startup to disabled."""
|
||||||
|
|
@ -18,27 +11,28 @@ def disable_service(service_name):
|
||||||
|
|
||||||
def disable_windows_updates():
|
def disable_windows_updates():
|
||||||
"""Disable windows updates and clear SoftwareDistribution folder."""
|
"""Disable windows updates and clear SoftwareDistribution folder."""
|
||||||
# Stop Windows update service
|
update_folders = [
|
||||||
stop_service('wuauserv')
|
r'{WINDIR}\SoftwareDistribution'.format(**global_vars['Env']),
|
||||||
disable_service('wuauserv')
|
r'{SYSTEMDRIVE}\$WINDOWS.~BT'.format(**global_vars['Env']),
|
||||||
|
]
|
||||||
|
|
||||||
# Stop Background Intelligent Transfer Service
|
# Stop services
|
||||||
try:
|
for service in ('wuauserv', 'bits'):
|
||||||
stop_service('bits')
|
stop_service(service)
|
||||||
disable_service('bits')
|
disable_service(service)
|
||||||
except Exception:
|
|
||||||
# Going to ignore these errors
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Delete update folders
|
# Delete update folders
|
||||||
for folder_path in UPDATE_FOLDERS:
|
for folder_path in update_folders:
|
||||||
if os.path.exists(folder_path):
|
if os.path.exists(folder_path):
|
||||||
shutil.rmtree(folder_path)
|
shutil.rmtree(folder_path)
|
||||||
|
|
||||||
|
|
||||||
def enable_service(service_name):
|
def enable_service(service_name):
|
||||||
"""Set service startup to enabled."""
|
"""Set service startup to enabled."""
|
||||||
|
try:
|
||||||
run_program(['sc', 'config', service_name, 'start=', 'automatic'])
|
run_program(['sc', 'config', service_name, 'start=', 'automatic'])
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
run_program(['sc', 'config', service_name, 'start=', 'auto'])
|
||||||
|
|
||||||
|
|
||||||
def enable_windows_updates():
|
def enable_windows_updates():
|
||||||
|
|
@ -49,7 +43,7 @@ def enable_windows_updates():
|
||||||
|
|
||||||
def stop_service(service_name):
|
def stop_service(service_name):
|
||||||
"""Stop service."""
|
"""Stop service."""
|
||||||
run_program(['net', 'stop', service_name])
|
run_program(['net', 'stop', service_name], check=False)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue