PoshCode Logo PowerShell Code Repository

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

    
1+
function get-windowsproductkey([string]$computer)
2+
{
3+
$Reg = [WMIClass] ("\\" + $computer + "\root\default:StdRegProv")
4+
$values = [byte[]]($reg.getbinaryvalue(2147483650,"SOFTWARE\Microsoft\Windows NT\CurrentVersion","DigitalProductId").uvalue)
5+
$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")
6+
$keyStartIndex = [int]52;
7+
$keyEndIndex = [int]($keyStartIndex + 15);
8+
$decodeLength = [int]29
9+
$decodeStringLength = [int]15
10+
$decodedChars = new-object char[] $decodeLength
11+
$hexPid = new-object System.Collections.ArrayList
12+
for ($i = $keyStartIndex; $i -le $keyEndIndex; $i++){ [void]$hexPid.Add($values[$i]) }
13+
for ( $i = $decodeLength - 1; $i -ge 0; $i--)
14+
    {
15+
     if (($i + 1) % 6 -eq 0){$decodedChars[$i] = '-'}
16+
     else
17+
       {
18+
        $digitMapIndex = [int]0
19+
        for ($j = $decodeStringLength - 1; $j -ge 0; $j--)
20+
        {
21+
            $byteValue = [int](($digitMapIndex * [int]256) -bor [byte]$hexPid[$j]);
22+
            $hexPid[$j] = [byte] ([math]::Floor($byteValue / 24));
23+
            $digitMapIndex = $byteValue % 24;
24+
            $decodedChars[$i] = $lookup[$digitMapIndex];
25+
         }
26+
        }
27+
     }
28+
$STR = ''
29+
$decodedChars | % { $str+=$_}
30+
$STR
31+
}
32+
get-windowsproductkey .

ContributeMost Recent Contributions (feed)

Contribute ... Next Page