欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PowerShell小技巧之讀取Windows產(chǎn)品密鑰

 更新時(shí)間:2014年10月13日 09:11:58   投稿:hebedich  
這篇文章主要給大家分享一段使用PowerShell讀取Windows產(chǎn)品密鑰的小技巧,非常的簡(jiǎn)單實(shí)用,有需要的朋友可以參考下。

之前大多數(shù)人可能用過(guò)VBS讀取Windows產(chǎn)品密鑰的VBS腳本,VBS腳本通常都比較隱晦、難懂,今天忙里偷閑,隨手寫了一個(gè)用于讀取Windows產(chǎn)品密鑰的PowerShell腳本。

代碼如下:

復(fù)制代碼 代碼如下:

 =====文件名:Get-WindowsProductKey.ps1=====
function Get-WindowsProductKey([string]$computer)
{

$comments =@'
author:fuhj(powershell#live.cn ,http://fuhaijun.com)
example: Get-WindowsProductKey .
'@
$reg = [WMIClass] ("\\" + $computer + "\root\default:StdRegProv")
$values = [byte[]]($reg.getbinaryvalue(2147483650,"SOFTWARE\Microsoft\Windows NT\CurrentVersion","DigitalProductId").uvalue)
$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")
$keyStartIndex = [int]52;
$keyEndIndex = [int]($keyStartIndex + 15);
$decodeLength = [int]29
$decodeStringLength = [int]15
$decodedChars = new-object char[] $decodeLength
$hexPid = new-object System.Collections.ArrayList
for ($i = $keyStartIndex; $i -le $keyEndIndex; $i++){ [void]$hexPid.Add($values[$i]) }
for ( $i = $decodeLength - 1; $i -ge 0; $i--)
    {
     if (($i + 1) % 6 -eq 0){$decodedChars[$i] = '-'}
     else
       {
        $digitMapIndex = [int]0
        for ($j = $decodeStringLength - 1; $j -ge 0; $j--)
        {
            $byteValue = [int](($digitMapIndex * [int]256) -bor [byte]$hexPid[$j]);
            $hexPid[$j] = [byte] ([math]::Floor($byteValue / 24));
            $digitMapIndex = $byteValue % 24;
            $decodedChars[$i] = $lookup[$digitMapIndex];
         }
        }
     }
$STR = ''
$decodedChars | % { $str+=$_}
$STR
}

Get-WindowsProductKey .

執(zhí)行效果如下:

相關(guān)文章

最新評(píng)論