我遇到了一个问题,因为我正在尝试部署一个列出 PC 主要数据的脚本,但不幸的是我无法获取任何内容的许可证密钥。公司中的所有计算机(IT 部门除外)都使用 Windows 7 Pro 并具有 powershell v 2.0。我需要获取许可证密钥,但没有任何想法。我尝试进入 cmd,然后“wmic path softwarelicensingservice get OA3xOriginalProductKey”,但这不起作用。有什么建议吗?
答案1
一个来自过去的人。
如何在不使用第三方软件的情况下获取 Windows 产品密钥
如果您丢失、无法找回或忘记了 Windows 8.1、Windows 8 或 Windows 7 操作系统的产品密钥的存储位置,请不要绝望。我想向您展示一个简单的解决方案,无需使用任何第三方软件即可从安装在您 PC 上的操作系统中提取产品密钥。
function Get-WindowsKey
{
## function to retrieve the Windows Product Key from any PC
## by Jakob Bindslet ([email protected])
param ($targets = ".")
$hklm = 2147483650
$regPath = "Software\Microsoft\Windows NT\CurrentVersion"
$regValue = "DigitalProductId"
Foreach ($target in $targets) {
$productKey = $null
$win32os = $null
$wmi = [WMIClass]"\\$target\root\default:stdRegProv"
$data = $wmi.GetBinaryValue($hklm,$regPath,$regValue)
$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 Caption -value $win32os.Caption
$obj | Add-Member Noteproperty CSDVersion -value $win32os.CSDVersion
$obj | Add-Member Noteproperty OSArch -value $win32os.OSArchitecture
$obj | Add-Member Noteproperty BuildNumber -value $win32os.BuildNumber
$obj | Add-Member Noteproperty RegisteredTo -value $win32os.RegisteredUser
$obj | Add-Member Noteproperty ProductID -value $win32os.SerialNumber
$obj | Add-Member Noteproperty ProductKey -value $productkey
$obj
}
}