WizardKit/.bin/Scripts/activate.ps1
Alan Mason d9dddebccb 2016-09: Retroactive Updates
Major .bin and extraction code overhaul

* All .cmd files now have code for searching the for the .bin folder
  * This starts at the script's parent folder and moves upward
  * If no .bin folder is found then print an error to the screen

* 7z has been replaced with 7za
  * This is for better handling of x32/x64 usage
  * This also fixed a few bugs with extracting ProduKey/MailPassView/etc
  * We no longer require the full power of 7z.exe/7z.dll
  * (Since wimlib-imagex will probably be used for WIM files soon-ish)

* Bugfixes
  * A few calls of pushd were unsafe (without quotes)
  * SFC scan no longer closes immediately
2017-11-17 00:51:54 -07:00

70 lines
2.2 KiB
PowerShell

# WK-Activate-w-BIOS-Key
#
## Finds the BIOS key using ProduKey and attempts to activate Windows with it
## NOTE: This script doesn't check if the key is accepted before activation.
## Init ##
$wd = $(Split-Path $MyInvocation.MyCommand.Path)
pushd "$wd"
. .\init.ps1
clear
$host.UI.RawUI.WindowTitle = "WK Activation Tool"
$logpath = "$WKPath\Info\$date"
md "$logpath" 2>&1 | out-null
$log = "$logpath\Activation.log"
$bin = (Get-Item $wd).Parent.FullName
$found_key = $false
$sz = "$bin\7-Zip\7za.exe"
$produkey = "$bin\tmp\ProduKey.exe"
# OS Check
. .\os_check.ps1
if ($arch -eq 64) {
$sz = "$bin\7-Zip\7za64.exe"
$produkey = "$bin\tmp\ProduKey64.exe"
}
## Extract ProduKey
md "$bin\tmp" 2>&1 | out-null
start -wait $sz -argumentlist @("e", "$bin\ProduKey.7z", "-otmp", "-aoa", "-pAbracadabra", "-bsp0", "-bso0") -workingdirectory "$bin" -nonewwindow
rm "$bin\tmp\ProduKey*.cfg"
sleep -s 1
## Get Key ##
$produkey_args = @(
"/nosavereg",
"/scomma", "$logpath\keys.csv",
"/WindowsKeys", "1",
"/OfficeKeys", "0",
"/IEKeys", "0",
"/SQLKeys", "0",
"/ExchangeKeys", "0"
)
start -wait $produkey -argumentlist $produkey_args -workingdirectory "$bin\tmp"
$keys = import-csv -header ("Name", "ID", "Key") "$logpath\keys.csv"
## Find BIOS Key and activate Windows with it
foreach ($k in $keys) {
$name = $k.Name
$key = $k.Key
if ($name -match 'BIOS' -and $key -match '^(\w{5}-\w{5}-\w{5}-\w{5}-\w{5})$') {
# NOTE: Assuming first match is correct and skip everything afterwards
$found = $true
wk-write "$name key found: $key" "$log"
if (ask " Activate Windows using this key?" "$log") {
start -wait "cscript.exe" -argumentlist @("slmgr.vbs", "/ipk", "$key", "//nologo") -nonewwindow -workingdirectory "$windir\System32"
start -wait "cscript.exe" -argumentlist @("slmgr.vbs", "/ato", "//nologo") -nonewwindow -workingdirectory "$windir\System32"
start -wait "cscript.exe" -argumentlist @("slmgr.vbs", "/xpr", "//nologo") -nonewwindow -workingdirectory "$windir\System32"
}
break
}
}
## Print error if necessary
if (! $found) {
wk-error "BIOS Key not found." "$log"
}
## Done ##
popd
pause "Press Enter to exit..."