## MAJOR refactoring in progress ##
# BROKEN SCRIPTS #
(These scripts need updated to use the new global_vars & try_and_print)
* user_data_transfer.py
* install_sw_bundle.py
* All Python scripts
* PLAN: Replace vars_wk with global_vars
* functions.py
* PLAN: Will hold (nearly?) all functions going forward
* Should simplify the remaining scripts
* (e.g. reset_browsers and sw_diagnostics both had a backup_browsers())
* PLAN: Move all program definitions to functions.py
* (e.g. vars_wk['SevenZip'] --> global_vars['Programs']['SevenZip'])
* Added major_exception()
* Should be called if anything goes wrong to alert user and provide info
* Added non_clobber_rename()
* Appends a number (if necessary) to avoid overwriting data
* Added popen_program()
* Removes subprocess req for sw_checklist
* Added try_and_print()
* Run a function and show CS/NS/etc
* Can add additional "result" strings via Exception classes
* Passes unrecognized args/kwargs to the function
* Used by scripts to standardize message formatting and error handling
* exit_script() now handles opening the log (if set) and killing caffeine.exe
* Refactored init_vars_wk/os code to work with global_vars
* Uses the try_and_print function for better formatting and error handling
* BREAKING: 'OS' vars now located in global_vars['OS'] (including 'Arch')
* OS labeled as 'outdated', 'very outdated', and 'unrecognized' as needed
* BREAKING: renamed PROGRAMS to TOOLS
* Expanded TOOLS
* Removed log_file as a required argument from all functions
* Removed vars_wk/global_vars as a required argument from all functions
* Removed unused WinPE functions
* Sorted functions
* user_checklist() (formerly reset_browsers())
* Most functions moved to functions.py (see above)
* Browsers
* Work has been split into backup, reset, and config sections
* Script now asks all questions before starting backup/reset/config
* Script now forces the homepage to DEFAULT_HOMEPAGE (set in functions.py)
* (i.e. it no longer asks first, it just does it)
* Current homepages are listed where possible before backup/reset/config
* Launch/Launchers
* Added QuickBooks support
* Removed launchers
* CPU-Z
* HWMonitor
* PerfMonitor2
* SanDisk Express Cache
* Shortcut Cleaner
* SuperAntiSpyware (SAS)
* Replaced Notepad2-Mod with Notepad++
69 lines
2 KiB
Python
69 lines
2 KiB
Python
# Wizard Kit: Transferred Keys
|
|
|
|
import os
|
|
import re
|
|
import subprocess
|
|
|
|
# Init
|
|
os.chdir(os.path.dirname(os.path.realpath(__file__)))
|
|
os.system('title Wizard Kit: Key Tool')
|
|
from functions import *
|
|
init_global_vars()
|
|
set_global_vars(LogFile='{LogDir}\\Transferred Keys.log'.format(**global_vars))
|
|
|
|
def abort():
|
|
print_warning('Aborted.')
|
|
exit_script(global_vars)
|
|
|
|
def extract_keys():
|
|
"""Extract keys from provided hives and return a dict."""
|
|
keys = {}
|
|
|
|
# Extract keys
|
|
extract_item('ProduKey')
|
|
for hive in find_software_hives():
|
|
print_standard(' Scanning {hive}...'.format(hive=hive))
|
|
_args = [
|
|
'/IEKeys', '0',
|
|
'/WindowsKeys', '1',
|
|
'/OfficeKeys', '1',
|
|
'/ExtractEdition', '1',
|
|
'/nosavereg',
|
|
'/regfile', hive,
|
|
'/scomma', '']
|
|
try:
|
|
_out = run_program(global_vars['Tools']['ProduKey'], _args)
|
|
for line in _out.stdout.decode().splitlines():
|
|
# Add key to keys under product only if unique
|
|
_tmp = line.split(',')
|
|
_product = _tmp[0]
|
|
_key = _tmp[2]
|
|
if _product not in keys:
|
|
keys[_product] = []
|
|
if _key not in keys[_product]:
|
|
keys[_product].append(_key)
|
|
except subprocess.CalledProcessError:
|
|
print_error(' Failed to extract any keys')
|
|
else:
|
|
for line in _out.stdout.decode().splitlines():
|
|
_match = re.search(r'', line, re.IGNORECASE)
|
|
|
|
return keys
|
|
|
|
if __name__ == '__main__':
|
|
stay_awake()
|
|
keys = extract_keys()
|
|
|
|
# Save Keys
|
|
if keys:
|
|
for product in sorted(keys):
|
|
print_standard('{product}:'.format(product=product))
|
|
for key in sorted(keys[product]):
|
|
print_standard(' {key}'.format(key=key))
|
|
else:
|
|
print_error('No keys found.')
|
|
|
|
# Done
|
|
print_standard('\nDone.')
|
|
pause("Press Enter to exit...")
|
|
exit_script()
|