I'd like to see the UDF include "known product" registry locations. ie... getproductkey(1) = XP, getproductkey(2) = OfficeXP, etc. But also leave it open to future registry locations that can be typed in like it is now.

But for my use I'll probably only use this for the XP key.


Code:
 
Break ON
$=SetOption("WrapAtEOL","ON")

function GetProductKey (optional $sProductID)
Dim $aiKeyChars[24],$bProductKey[15],$ilByte,$i,$sCDKey
if $sProductID=""
$sProductID=ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\Windows NT\CurrentVersion","DigitalProductID")
endif
$aiKeyChars = Split('B,C,D,F,G,H,J,K,M,P,Q,R,T,V,W,X,Y,2,3,4,6,7,8,9',',')

for $i = 0 to 14
$bProductKey[$i] = val("&"+substr($sProductID,$i*2+105,2))
next

$sCDKey = ""
For $ilByte = 24 To 0 Step -1
$nCur = 0

For $i=14 To 0 Step -1
$nCur = $nCur * 256 | $bProductKey[$i]
$bProductKey[$i] = Int($nCur / 24)
$nCur = $nCur Mod 24
Next
$sCDKey = $aiKeyChars[$nCur] + $sCDKey
If $ilByte Mod 5 = 0 And $ilByte <> 0 $sCDKey = "-" + $sCDKey EndIf
Next
$GetProductKey = $sCDKey
endfunction

;$dpi=ReadValue("HKEY_LOCAL_MACHINE\SOFTWARE\MICROSOFT\Windows NT\CurrentVersion","DigitalProductID")
;$key = get_product_key($dpi)
? "Windows Product Key: " + getproductkey()

? "Press any key..."
get $