= 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
}
$proctKey = $charsArray[$k] + $proctKey
If (($i % 5 -eq 0) -and ($i -ne 0)) {
$proctKey = "-" + $proctKey
}
}
$win32os = Get-WmiObject Win32_OperatingSystem -買粉絲puter $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 ProctKey -value $proctkey
$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 (daanno2@gmail.買粉絲)
param ($targets = ".")
$hklm = 2147483650
$regPath = "SOFTWARE\Microsoft\Microsoft SQL Server\110\Tools\Setup"
$regValue1 = "DigitalProctId"
$regValue2 = "PatchLevel"
$regValue3 = "Edition"
Foreach ($target in $targets) {
$proctKey = $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 en買粉絲ded 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
}
$proctKey = $charsArray[$k] + $proctKey
If (($i % 5 -eq 0) -and ($i -ne 0)) {
$proctKey = "-" + $proctKey
}
}
$win32os = Get-WmiObject Win32_OperatingSystem -買粉絲puter $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 ProctKey -value $proctkey
$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
ProctKey : *****-G8T4R-QW4XX-BVH62-
*****對于SQL Server 2000, 2005,由于手頭沒有環境,沒有測試;對于Office,Windows系統,應該也都可以通過類似的方式拿到序列號。
以上內容就是關于安裝完成后如何找回SQL Server實例安裝時的序列號,希望大家有所幫助。
您可能感興趣的文章:java生成申請單序列號的實現方法SQL Server自動生成日期加數字的序列號.買粉絲獲取硬件信息_CPU序列號C#獲得MAC地址(網卡序列號)的實現代碼C#利用win32 Api 修改本地系統時間、獲取硬盤序列號mysql簡單實現查詢結果添加序列號的方法PowerShell中獲取Windows系統序列號的腳本分享C#獲取U盤序列號的方法C#實現讀取指定盤符硬盤序列號的方法ORACLE實現自定義序列號生成的方法
2024-07-29 04:02
2024-07-29 03:53
2024-07-29 03:50
2024-07-29 03:42
2024-07-29 03:33
2024-07-29 03:03