Added SFC scan
This commit is contained in:
parent
b41027562a
commit
2678ce77da
3 changed files with 85 additions and 41 deletions
|
|
@ -1,40 +0,0 @@
|
||||||
# Wizard Kit: Check, and possibly repair, system file health via SFC
|
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
# Init
|
|
||||||
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
|
|
||||||
from functions.repairs import *
|
|
||||||
init_global_vars()
|
|
||||||
os.system('title {}: SFC Tool'.format(KIT_NAME_FULL))
|
|
||||||
set_log_file('SFC Tool.log')
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
try:
|
|
||||||
stay_awake()
|
|
||||||
clear_screen()
|
|
||||||
print_info('{}: SFC Tool\n'.format(KIT_NAME_FULL))
|
|
||||||
other_results = {
|
|
||||||
'Error': {
|
|
||||||
'CalledProcessError': 'Unknown Error',
|
|
||||||
},
|
|
||||||
'Warning': {
|
|
||||||
'GenericRepair': 'Repaired',
|
|
||||||
}}
|
|
||||||
if ask('Run a SFC scan now?'):
|
|
||||||
try_and_print(message='SFC scan...',
|
|
||||||
function=run_sfc_scan, other_results=other_results)
|
|
||||||
else:
|
|
||||||
abort()
|
|
||||||
|
|
||||||
# Done
|
|
||||||
print_standard('\nDone.')
|
|
||||||
pause('Press Enter to exit...')
|
|
||||||
exit_script()
|
|
||||||
except SystemExit as sys_exit:
|
|
||||||
exit_script(sys_exit.code)
|
|
||||||
except:
|
|
||||||
major_exception()
|
|
||||||
|
|
||||||
# vim: sts=2 sw=2 ts=2
|
|
||||||
35
scripts/sfc_scan.py
Normal file
35
scripts/sfc_scan.py
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
"""Wizard Kit: Check, and possibly repair, system file health via SFC"""
|
||||||
|
# vim: sts=2 sw=2 ts=2
|
||||||
|
|
||||||
|
import wk
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Run SFC and report result."""
|
||||||
|
title = f'{wk.cfg.main.KIT_NAME_FULL}: SFC Tool'
|
||||||
|
try_print = wk.std.TryAndPrint()
|
||||||
|
wk.std.clear_screen()
|
||||||
|
wk.std.set_title(title)
|
||||||
|
wk.std.print_info(title)
|
||||||
|
print('')
|
||||||
|
|
||||||
|
# Ask
|
||||||
|
if not wk.std.ask('Run a SFC scan now?'):
|
||||||
|
wk.std.abort()
|
||||||
|
print('')
|
||||||
|
|
||||||
|
# Run
|
||||||
|
try_print.run('SFC scan...', wk.os.win.run_sfc_scan)
|
||||||
|
|
||||||
|
# Done
|
||||||
|
print('Done')
|
||||||
|
wk.std.pause('Press Enter to exit...')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except SystemExit:
|
||||||
|
raise
|
||||||
|
except: #pylint: disable=bare-except
|
||||||
|
wk.std.major_exception()
|
||||||
|
|
@ -1,9 +1,22 @@
|
||||||
"""WizardKit: Windows Functions"""
|
"""WizardKit: Windows Functions"""
|
||||||
# vim: sts=2 sw=2 ts=2
|
# vim: sts=2 sw=2 ts=2
|
||||||
|
|
||||||
from wk.std import run_program
|
import logging
|
||||||
|
import os
|
||||||
|
import pathlib
|
||||||
|
import re
|
||||||
|
import time
|
||||||
|
|
||||||
|
from wk import cfg
|
||||||
|
from wk.io import non_clobber_path
|
||||||
|
from wk.std import (
|
||||||
|
GenericError,
|
||||||
|
GenericWarning,
|
||||||
|
run_program,
|
||||||
|
)
|
||||||
|
|
||||||
# STATIC VARIABLES
|
# STATIC VARIABLES
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
REG_MSISERVER = r'HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Network\MSIServer'
|
REG_MSISERVER = r'HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Network\MSIServer'
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -38,5 +51,41 @@ def enable_safemode_msi():
|
||||||
run_program(cmd)
|
run_program(cmd)
|
||||||
|
|
||||||
|
|
||||||
|
def run_sfc_scan():
|
||||||
|
"""Run SFC and save results."""
|
||||||
|
cmd = ['sfc', '/scannow']
|
||||||
|
log_path = pathlib.Path(
|
||||||
|
'{drive}/{short}/Logs/{date}/Tools/SFC.log'.format(
|
||||||
|
drive=os.environ.get('SYSTEMDRIVE', 'C:'),
|
||||||
|
short=cfg.main.KIT_NAME_SHORT,
|
||||||
|
date=time.strftime('%Y-%m-%d'),
|
||||||
|
))
|
||||||
|
err_path = log_path.with_suffix('.err')
|
||||||
|
|
||||||
|
# Run SFC
|
||||||
|
proc = run_program(cmd, check=False)
|
||||||
|
|
||||||
|
# Fix paths
|
||||||
|
log_path = non_clobber_path(log_path)
|
||||||
|
err_path = non_clobber_path(err_path)
|
||||||
|
|
||||||
|
# Save output
|
||||||
|
output = proc.stdout.replace('\0', '')
|
||||||
|
errors = proc.stderr.replace('\0', '')
|
||||||
|
os.makedirs(log_path.parent, exist_ok=True)
|
||||||
|
with open(log_path, 'w') as _f:
|
||||||
|
_f.write(output)
|
||||||
|
with open(err_path, 'w') as _f:
|
||||||
|
_f.write(errors)
|
||||||
|
|
||||||
|
# Check result
|
||||||
|
if re.findall(r'did\s+not\s+find\s+any\s+integrity\s+violations', output):
|
||||||
|
pass
|
||||||
|
elif re.findall(r'successfully\s+repaired\s+them', output):
|
||||||
|
raise GenericWarning('Repaired')
|
||||||
|
else:
|
||||||
|
raise GenericError
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print("This file is not meant to be called directly.")
|
print("This file is not meant to be called directly.")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue