PoshCode Logo PowerShell Code Repository

Difference between
modified post 6675 by Dominik on Sun 8th Jan 13:18 and
original post 6673 by Dominik on Sun 8th Jan 13:17
Showold version | new version | both versions

    
11
function get-windowsproductkey([string]$computer)
22
{
33
$Reg = [WMIClass] ("\\" + $computer + "\root\default:StdRegProv")
44
$values = [byte[]]($reg.getbinaryvalue(2147483650,"SOFTWARE\Microsoft\Windows NT\CurrentVersion","DigitalProductId").uvalue)
55
$lookup = [char[]]("B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9")
66
$keyStartIndex = [int]52;
77
$keyEndIndex = [int]($keyStartIndex + 15);
88
$decodeLength = [int]29
99
$decodeStringLength = [int]15
1010
$decodedChars = new-object char[] $decodeLength
1111
$hexPid = new-object System.Collections.ArrayList
1212
for ($i = $keyStartIndex; $i -le $keyEndIndex; $i++){ [void]$hexPid.Add($values[$i]) }
1313
for ( $i = $decodeLength - 1; $i -ge 0; $i--)
1414
    {
1515
     if (($i + 1) % 6 -eq 0){$decodedChars[$i] = '-'}
1616
     else
1717
       {
1818
        $digitMapIndex = [int]0
1919
        for ($j = $decodeStringLength - 1; $j -ge 0; $j--)
2020
        {
2121
            $byteValue = [int](($digitMapIndex * [int]256) -bor [byte]$hexPid[$j]);
2222
            $hexPid[$j] = [byte] ([math]::Floor($byteValue / 24));
2323
            $digitMapIndex = $byteValue % 24;
2424
            $decodedChars[$i] = $lookup[$digitMapIndex];
2525
         }
2626
        }
2727
     }
2828
$STR = ''
2929
$decodedChars | % { $str+=$_}
3030
$STR
3131
}
3232
get-windowsproductkey .

ContributeMost Recent Contributions (feed)

Contribute ... Next Page