英文站上转载的,正确与否未知。MsgBox(0,0, ProductKey())
Func ProductKey()
Local $sKey[29], $Value = 0, $hi = 0, $n = 0, $i = 0, $dlen = 29, $slen = 15, $Result, $bKey, $iKeyOffset = 52, $RegKey
$bKey = RegRead("HKLM64\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductId")
If Not BinaryLen($bKey) Then Return ""
Local $aKeys[BinaryLen($bKey)]
For $i = 0 To UBound($aKeys) - 1
$aKeys[$i] = Int(BinaryMid($bKey, $i + 1, 1))
Next
Local Const $isWin8 = BitAND(BitShift($aKeys[$iKeyOffset + 14], 3), 1)
$aKeys[$iKeyOffset + 14] = BitOR(BitAND($aKeys[$iKeyOffset + 14], 0xF7), BitShift(BitAND($isWin8, 2), -2))
$i = 24
Local $sChars = "BCDFGHJKMPQRTVWXY2346789", $iCur, $iX, $sKeyOutput, $iLast
While $i > -1
$iCur = 0
$iX = 14
While $iX > -1
$iCur = BitShift($iCur, -8)
$iCur = $aKeys[$iX + $iKeyOffset] + $iCur
$aKeys[$iX + $iKeyOffset] = Int($iCur / 24)
$iCur = Mod($iCur, 24)
$iX -= 1
WEnd
$i -= 1
$sKeyOutput = StringMid($sChars, $iCur + 1, 1) & $sKeyOutput
$iLast = $iCur
WEnd
If $isWin8 Then
$sKeyOutput = StringMid($sKeyOutput, 2, $iLast) & "N" & StringTrimLeft($sKeyOutput, $iLast + 1)
EndIf
Return StringRegExpReplace($sKeyOutput, '(\w{5})(\w{5})(\w{5})(\w{5})(\w{5})', '\1-\2-\3-\4-\5')
EndFunc ;==>ProductKey
|