裝置完成後若何找回SQL Server實例裝置時的序列號。本站提示廣大學習愛好者:(裝置完成後若何找回SQL Server實例裝置時的序列號)文章只能為提供參考,不一定能成為您想要的結果。以下是裝置完成後若何找回SQL Server實例裝置時的序列號正文
當須要再次裝置SQL Server時,假如序列號找不到了,可以試著從曾經裝置的實例裡找回序列號,由於裝置完SQL Server後,序列號(Product Key)被保留在注冊內外;
MSDN定閱下載的裝置包是內置序列號的,則沒有這個困擾。
一. 序列號保留在哪
經由過程無文檔記錄的擴大存儲進程xp_regread讀取注冊表:
--For SQL Server 2008, 2008 R2 use master GO exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Microsoft SQL Server\100\Tools\Setup','ProductCode' exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Microsoft SQL Server\100\Tools\Setup','DigitalProductID' GO --For SQL Server 2012 use master GO exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Microsoft SQL Server\110\Tools\Setup','ProductCode' exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Microsoft SQL Server\110\Tools\Setup','DigitalProductId' GO
不要被ProductCode困惑,就算只裝置了SQL Server客戶端,注冊內外也會有這個鍵值,其實不是序列號,DigitalProductID才是,但經由了Base24編碼,須要解碼才行。
可以看到,關於分歧版本,注冊表的途徑紛歧樣,然則鍵是分歧的。
Express版是收費的,沒有序列號,從而注冊表也沒DigitalProductID這個鍵。
二. 若何解碼序列號
1. Base24, Base64 編碼簡介
能夠許多人據說過Base64編碼,它用於比較較長的字符串停止編碼,以便利傳輸;
Base24編碼重要運用在序列號生成上,二者的完成思緒是相似的,只是編碼的形式有點變更。
Base64所對應的編碼表是:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
合計64個字符。
Base24所對應的編碼表是:
BCDFGHJKMPQRTVWXY2346789
合計24個字符,這裡重要去失落了一些關於序列號來講不輕易辨認和輕易混雜的字符。
SQL Server的序列號采取的是Base24編碼,對編碼後的字符停止解碼,便可以獲得原文。
編碼/解碼其實不是加密/解密,沒有秘鑰的說法,只要字符轉換的規矩,Base24, Base64具體的算法可以在網上找到。
2. 應用Powershell 解碼
以下powershell函數用於解碼/找回SQL Server序列號,在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 } } $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序列號裡字符的格局產生了變更,$binArray = ($data.uValue)[0..16] 分歧於SQL Server 2008的$binArray = ($data.uValue)[52..66],同時別忘了改下注冊表途徑$regPath = "SOFTWARE\Microsoft\Microsoft SQL Server\110\Tools\Setup",修正後以下,在SQL Server 2012實例上測試經由過程:
function Get-SQLServerKey { ## function to retrieve the license key of a SQL 2012 Server. ## by Jakob Bindslet ([email protected]) ## 2012 Modification by Xian Wang ([email protected]) 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 } }
3. 挪用powershell函數並輸入序列號
翻開powershell,把下面的函數貼出來,回車,輸出Get-SQLServerKey 並回車;
或許把下面的函數存為.ps1文件直接援用:
PS C:\Windows\system32> . C:\Users\username\Desktop\pk.ps1 PS C:\Windows\system32> Get-SQLserverKey
輸入成果以下,首尾幾個字符被工資改成星號,沒有貼出來。
Computer : . OSCaption : Microsoft Windows Server 2012 R2 Standard OSArch : 64-bit SQLver : 11.2.5058.0 SQLedition : Developer Edition ProductKey : *****-G8T4R-QW4XX-BVH62-*****
關於SQL Server 2000, 2005,因為手頭沒有情況,沒有測試;關於Office,Windows體系,應當也都可以經由過程相似的方法拿到序列號。
以上內容就是關於裝置完成後若何找回SQL Server實例裝置時的序列號,願望年夜家有所贊助。