Add timezone check to Auto Repairs

This commit is contained in:
2Shirt 2021-05-07 18:18:38 -06:00
parent 59fd85429c
commit b7b8f20e24
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
2 changed files with 26 additions and 1 deletions

View file

@ -414,5 +414,19 @@ def stop_service(service_name):
raise GenericError(f'Failed to stop service {service_name}')
# Date / Time functions
def get_timezone():
"""Get current timezone using tzutil, returns str."""
cmd = ['tzutil', '/g']
proc = run_program(cmd, check=False)
return proc.stdout
def set_timezone(zone):
"""Set current timezone using tzutil."""
cmd = ['tzutil', '/s', zone]
run_program(cmd, check=False)
if __name__ == '__main__':
print("This file is not meant to be called directly.")

View file

@ -12,7 +12,7 @@ import time
from subprocess import CalledProcessError, DEVNULL
from wk.cfg.main import KIT_NAME_FULL, KIT_NAME_SHORT
from wk.cfg.main import KIT_NAME_FULL, KIT_NAME_SHORT, WINDOWS_TIME_ZONE
from wk.exe import (
get_procs,
run_program,
@ -23,6 +23,8 @@ from wk.io import delete_folder, get_path_obj, rename_item
from wk.kit.tools import download_tool, get_tool_path, run_tool
from wk.log import format_log_path, update_log_path
from wk.os.win import (
get_timezone,
set_timezone,
reg_delete_value,
reg_read_value,
reg_set_value,
@ -288,6 +290,15 @@ def init_session(options):
"""Initialize Auto Repairs session."""
reg_set_value('HKCU', AUTO_REPAIR_KEY, 'SessionStarted', 1, 'DWORD')
# Check timezone
zone = get_timezone()
msg = (
'The timezone is currently set to '
f'{zone}, switch it to {WINDOWS_TIME_ZONE}?'
)
if zone != WINDOWS_TIME_ZONE and ask(msg):
set_timezone(WINDOWS_TIME_ZONE)
# Create logon task for Auto Repairs
cmd = [
'schtasks', '/create', '/f',