Added outer activation script

This commit is contained in:
2Shirt 2019-09-22 18:43:21 -07:00
parent f27f3024e8
commit 1cfd8fb7b4
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C
5 changed files with 50 additions and 78 deletions

31
scripts/activate.py Normal file
View file

@ -0,0 +1,31 @@
"""Wizard Kit: Activate Windows using a BIOS key"""
# vim: sts=2 sw=2 ts=2
import wk
def main():
"""Attempt to activate Windows and show result."""
title = f'{wk.cfg.main.KIT_NAME_FULL}: Activation Tool'
try_print = wk.std.TryAndPrint()
wk.std.clear_screen()
wk.std.set_title(title)
wk.std.print_info(title)
print('')
# Attempt activation
try_print.run('Attempting activation...', wk.os.win.activate_with_bios)
# Done
print('')
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()

View file

@ -1,63 +0,0 @@
# Wizard Kit: Activate Windows using various methods
import os
import sys
# Init
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
from functions.activation import *
init_global_vars()
os.system('title {}: Windows Activation Tool'.format(KIT_NAME_FULL))
if __name__ == '__main__':
try:
stay_awake()
clear_screen()
print_info('{}: Windows Activation Tool\n'.format(KIT_NAME_FULL))
# Bail early if already activated
if windows_is_activated():
print_info('This system is already activated')
sleep(5)
exit_script()
other_results = {
'Error': {
'BIOSKeyNotFoundError': 'BIOS key not found.',
}}
# Determine activation method
activation_methods = [
{'Name': 'Activate with BIOS key', 'Function': activate_with_bios},
]
if global_vars['OS']['Version'] not in ('8', '8.1', '10'):
activation_methods[0]['Disabled'] = True
actions = [
{'Name': 'Quit', 'Letter': 'Q'},
]
while True:
selection = menu_select(
'{}: Windows Activation Menu'.format(KIT_NAME_FULL),
main_entries=activation_methods, action_entries=actions)
if (selection.isnumeric()):
result = try_and_print(
message = activation_methods[int(selection)-1]['Name'],
function = activation_methods[int(selection)-1]['Function'],
other_results=other_results)
if result['CS']:
break
else:
sleep(2)
elif selection == 'Q':
exit_script()
# Done
print_success('\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

View file

@ -63,7 +63,7 @@ def delete_item(path, force=False, ignore_errors=False):
os.remove(path)
def non_clobbering_path(path):
def non_clobber_path(path):
"""Update path as needed to non-existing path, returns pathlib.Path."""
LOG.debug('path: %s', path)
path = pathlib.Path(path)

View file

@ -1,7 +1,9 @@
"""WizardKit: os module init"""
# vim: sts=2 sw=2 ts=2
import os
import platform
if os.name == 'nt':
#if platform.system() == 'Darwin':
#if platform.system() == 'Linux':
if platform.system() == 'Windows':
from wk.os import win

View file

@ -17,7 +17,7 @@ from wk.std import GenericError, GenericWarning, sleep
# STATIC VARIABLES
LOG = logging.getLogger(__name__)
REG_MSISERVER = r'HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot\Network\MSIServer'
SLMGR = pathlib.Path(f'{os.environ("SYSTEMROOT")}/System32/slmgr.vbs')
SLMGR = pathlib.Path(f'{os.environ.get("SYSTEMROOT")}/System32/slmgr.vbs')
# Functions
@ -41,6 +41,10 @@ def activate_with_bios():
if not bios_key:
raise GenericError('BIOS key not found.')
# Check if activation is needed
if is_activated():
raise GenericWarning('System already activated')
# Install Key
cmd = ['cscript', '//nologo', SLMGR, '/ipk', bios_key]
run_program(cmd, check=False)
@ -52,7 +56,7 @@ def activate_with_bios():
sleep(5)
# Check status
if not windows_is_activated():
if not is_activated():
raise GenericError('Activation Failed')
@ -96,6 +100,14 @@ def get_activation_string():
return act_str
def is_activated():
"""Check if Windows is activated via slmgr.vbs and return bool."""
act_str = get_activation_string()
# Check result.
return act_str and 'permanent' in act_str
def run_sfc_scan():
"""Run SFC and save results."""
cmd = ['sfc', '/scannow']
@ -132,15 +144,5 @@ def run_sfc_scan():
raise GenericError
def windows_is_activated():
"""Check if Windows is activated via slmgr.vbs and return bool."""
cmd = ['cscript', '//nologo', SLMGR, '/xpr']
result = run_program(cmd, check=False)
act_str = result.stdout
# Check result.
return bool(act_str and 'permanent' in act_str)
if __name__ == '__main__':
print("This file is not meant to be called directly.")