## MAJOR refactoring done ##
* All .cmd Command scripts
* Brandind / Settings variables now set via .bin/Scripts/settings/main.py
* Window titles now set using KIT_FULL_NAME
* All .py Python scripts
* All ClientDir paths should now use KIT_SHORT_NAME
* Long lines wrapped to better follow PEP8
* String formatting now more consistant
* Updated run_program() and popen_program() calls to use lists
* (e.g. cmd = ['', '', '']; run_program(cmd))
** Should improve clarity IMO
* Update window titles AFTER init_global_vars() so KIT_FULL_NAME can be used
* Branding / Settings
* Support tech now configurable
* (e.g. "Please let {tech} know and they'll look into it")
* Timezone now configurable
* Upload info can now be disabled/enabled in .bin/Scripts/settings/main.py
* CHKDSK
* Combined read-only and fix scripts and added menu
* DISM
* Combined ScanHealth and RestoreHealth scripts and added menu
* functions/common.py
* BREAKING: run_program() and popen_program() no longer accept 'args' variable
* Misc
* Removed Win7 NVMe launcher
* Never used and Win7 is deprecated
* Removed "DeviceRemover" and "Display Driver Uninstaller" launchers
* Both cut too deep and were not useful
* Removed Nirsoft utilities and Sysinternals Suite launchers
* Too many tools unused.
* Added .url links to the websites in case the tools are needed
* Replaced WinDirStat with TreeSizeFree
* Replaced Q-Dir launcher with XYplorer launcher
* Q-Dir was running into issues on Windows 10
* Removed C.IntRep, ESET, and MBAM launchers from "OSR & VR"
* Removed JRT
* Deprecated and discontinued by MBAM
* Removed unsupported QuickBooks launchers (2014 and older)
* Removed unsupported Office launchers (2010 and 2013\365)
* Removed "Revo Uninstaller" launcher
* Removed infrequently used tools from "Diagnostics"
* Auslogics DiskDefrag
* BatteryInfoView
* BIOSCodes
* GpuTest
* HeavyLoad
* Bugfixes
* major_exception() try-blocks should catch CTL+c again
* Allows for manual script bailing
111 lines
3.4 KiB
Python
111 lines
3.4 KiB
Python
# Wizard Kit: Functions - Product Keys
|
|
|
|
from functions.common import *
|
|
|
|
# Regex
|
|
REGEX_REGISTRY_DIRS = re.compile(
|
|
r'^(config$|RegBack$|System32$|Transfer|Win)',
|
|
re.IGNORECASE)
|
|
REGEX_SOFTWARE_HIVE = re.compile(r'^Software$', re.IGNORECASE)
|
|
|
|
def extract_keys():
|
|
"""Extract keys from provided hives and return a dict."""
|
|
keys = {}
|
|
|
|
# Extract keys
|
|
extract_item('ProduKey', silent=True)
|
|
for hive in find_software_hives():
|
|
cmd = [
|
|
global_vars['Tools']['ProduKey'],
|
|
'/IEKeys', '0',
|
|
'/WindowsKeys', '1',
|
|
'/OfficeKeys', '1',
|
|
'/ExtractEdition', '1',
|
|
'/nosavereg',
|
|
'/regfile', hive,
|
|
'/scomma', '']
|
|
try:
|
|
out = run_program(cmd)
|
|
except subprocess.CalledProcessError:
|
|
# Ignore and return empty dict
|
|
pass
|
|
else:
|
|
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)
|
|
|
|
# Done
|
|
return keys
|
|
|
|
def list_clientdir_keys():
|
|
"""List product keys found in hives inside the ClientDir."""
|
|
keys = extract_keys()
|
|
key_list = []
|
|
if keys:
|
|
for product in sorted(keys):
|
|
key_list.append(product)
|
|
for key in sorted(keys[product]):
|
|
key_list.append(' {key}'.format(key=key))
|
|
else:
|
|
key_list.append('No keys found.')
|
|
|
|
return key_list
|
|
|
|
def find_software_hives():
|
|
"""Search for transferred SW hives and return a list."""
|
|
hives = []
|
|
search_paths = [global_vars['ClientDir']]
|
|
|
|
while len(search_paths) > 0:
|
|
for item in os.scandir(search_paths.pop(0)):
|
|
if item.is_dir() and REGEX_REGISTRY_DIRS.search(item.name):
|
|
search_paths.append(item.path)
|
|
if item.is_file() and REGEX_SOFTWARE_HIVE.search(item.name):
|
|
hives.append(item.path)
|
|
|
|
return hives
|
|
|
|
def get_product_keys():
|
|
"""List product keys from saved report."""
|
|
keys = []
|
|
log_file = r'{LogDir}\Product Keys (ProduKey).txt'.format(**global_vars)
|
|
with open (log_file, 'r') as f:
|
|
for line in f.readlines():
|
|
if re.search(r'^Product Name', line):
|
|
line = re.sub(r'^Product Name\s+:\s+(.*)', r'\1', line.strip())
|
|
keys.append(line)
|
|
|
|
if keys:
|
|
return keys
|
|
else:
|
|
return ['No product keys found']
|
|
|
|
def run_produkey():
|
|
"""Run ProduKey and save report in the ClientDir."""
|
|
extract_item('ProduKey', silent=True)
|
|
log_file = r'{LogDir}\Product Keys (ProduKey).txt'.format(**global_vars)
|
|
if not os.path.exists(log_file):
|
|
# Clear current configuration
|
|
for config in ['ProduKey.cfg', 'ProduKey64.cfg']:
|
|
config = r'{BinDir}\ProduKey\{config}'.format(
|
|
config=config, **global_vars)
|
|
try:
|
|
if os.path.exists(config):
|
|
os.remove(config)
|
|
except Exception:
|
|
pass
|
|
cmd = [
|
|
global_vars['Tools']['ProduKey'],
|
|
'/nosavereg',
|
|
'/stext',
|
|
log_file]
|
|
run_program(cmd, check=False)
|
|
|
|
if __name__ == '__main__':
|
|
print("This file is not meant to be called directly.")
|