找回已激活的SQL秘钥

    之前激活的秘钥已经忘记了,只能想办法从老机器上尝试找回秘钥。查了下用powershell会比较方便,也有现成的函数。

支持SQL Server 2008, 2008 R2

function Get-SQLServerKey {

## function to retrieve the license key of a SQL 2008 Server.

param ($targets = ".")

$hklm = 2147483650

$regPath = "SOFTWARE\Microsoft\Microsoft SQL Server\100\Tools\Setup"

$regValue1 = "DigitalProductId"

$regValue2 = "PatchLevel"

$regValue3 = "Edition"

Foreach ($target in $targets) {

$productKey = $null

$win32os = $null

$wmi = [WMIClass]"\\$target\root\default:stdRegProv"

$data = $wmi.GetBinaryValue($hklm,$regPath,$regValue1)

[string]$SQLver = $wmi.GetstringValue($hklm,$regPath,$regValue2).svalue

[string]$SQLedition = $wmi.GetstringValue($hklm,$regPath,$regValue3).svalue

$binArray = ($data.uValue)[52..66]

$charsArray = "B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9"

## decrypt base24 encoded binary data

For ($i = 24; $i -ge 0; $i--) {

$k = 0

For ($j = 14; $j -ge 0; $j--) {

$k = $k * 256 -bxor $binArray[$j]

$binArray[$j] = [math]::truncate($k / 24)

$k = $k % 24

}

$productKey = $charsArray[$k] + $productKey

If (($i % 5 -eq 0) -and ($i -ne 0)) {

$productKey = "-" + $productKey

}

}

$productKey = $charsArray[$k] + $productKey

If (($i % 5 -eq 0) -and ($i -ne 0)) {

$productKey = "-" + $productKey

}

}

$win32os = Get-WmiObject Win32_OperatingSystem -computer $target

$obj = New-Object Object

$obj | Add-Member Noteproperty Computer -value $target

$obj | Add-Member Noteproperty OSCaption -value $win32os.Caption

$obj | Add-Member Noteproperty OSArch -value $win32os.OSArchitecture

$obj | Add-Member Noteproperty SQLver -value $SQLver

$obj | Add-Member Noteproperty SQLedition -value $SQLedition

$obj | Add-Member Noteproperty ProductKey -value $productkey

$obj

}

}

支持SQL Server 2012

function Get-SQLServerKey {

## function to retrieve the license key of a SQL 2012 Server.

param ($targets = ".")

$hklm = 2147483650

$regPath = "SOFTWARE\Microsoft\Microsoft SQL Server\110\Tools\Setup"

$regValue1 = "DigitalProductId"

$regValue2 = "PatchLevel"

$regValue3 = "Edition"

Foreach ($target in $targets) {

$productKey = $null

$win32os = $null

$wmi = [WMIClass]"\\$target\root\default:stdRegProv"

$data = $wmi.GetBinaryValue($hklm,$regPath,$regValue1)

[string]$SQLver = $wmi.GetstringValue($hklm,$regPath,$regValue2).svalue

[string]$SQLedition = $wmi.GetstringValue($hklm,$regPath,$regValue3).svalue

$binArray = ($data.uValue)[0..16]

$charsArray = "B","C","D","F","G","H","J","K","M","P","Q","R","T","V","W","X","Y","2","3","4","6","7","8","9"

## decrypt base24 encoded binary data

For ($i = 24; $i -ge 0; $i--) {

$k = 0

For ($j = 14; $j -ge 0; $j--) {

$k = $k * 256 -bxor $binArray[$j]

$binArray[$j] = [math]::truncate($k / 24)

$k = $k % 24

}

$productKey = $charsArray[$k] + $productKey

If (($i % 5 -eq 0) -and ($i -ne 0)) {

$productKey = "-" + $productKey

}

}

$win32os = Get-WmiObject Win32_OperatingSystem -computer $target

$obj = New-Object Object

$obj | Add-Member Noteproperty Computer -value $target

$obj | Add-Member Noteproperty OSCaption -value $win32os.Caption

$obj | Add-Member Noteproperty OSArch -value $win32os.OSArchitecture

$obj | Add-Member Noteproperty SQLver -value $SQLver

$obj | Add-Member Noteproperty SQLedition -value $SQLedition

$obj | Add-Member Noteproperty ProductKey -value $productkey

$obj

}

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,765评论 18 399
  • 背景 一年多以前我在知乎上答了有关LeetCode的问题, 分享了一些自己做题目的经验。 张土汪:刷leetcod...
    土汪阅读 12,769评论 0 33
  • 不支持上传文件,所以就复制过来了。作者信息什么的都没删。对前端基本属于一窍不通,所以没有任何修改,反正用着没问题就...
    全栈在路上阅读 1,998评论 0 2
  • 感谢每一个出现在我生命中的人,因了你们,我的生命充满温暖,早安
    1清明1阅读 287评论 0 0
  • 三月三,春意盎然 细雨润酥, 竹林叠翠 山野桃花始盛开,敢为先 美梦要成真 攻书莫畏难 一年之计躲藏进,明媚春光 ...
    观海听涛_6ae8阅读 498评论 0 2