this question(Windowsプロダクトキーの取得方法を尋ねる)の後には、さまざまな方法から得られた矛盾した情報があるようです。この質問は、なぜ同じ値を返すべきなのかという違いがあるのかと問いただしています。このVBSスクリプトにWindowsプロダクトキー - さまざまなテクニックからの異なる回答
これらの2つの方法...
PowerShellの
(Get-WmiObject -query ‘select * from SoftwareLicensingService’).OA3xOriginalProductKey
CMD
wmic path softwarelicensingservice get OA3xOriginalProductKey
リターン異なる結果を...
Set WshShell = CreateObject("WScript.Shell")
MsgBox ConvertToKey(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"))
Function ConvertToKey(Key)
Const KeyOffset = 52
i = 28
Chars = "BCDFGHJKMPQRTVWXY2346789"
Do
Cur = 0
x = 14
Do
Cur = Cur * 256
Cur = Key(x + KeyOffset) + Cur
Key(x + KeyOffset) = (Cur \ 24) And 255
Cur = Cur Mod 24
x = x - 1
Loop While x >= 0
i = i - 1
KeyOutput = Mid(Chars, Cur + 1, 1) & KeyOutput
If (((29 - i) Mod 6) = 0) And (i <> -1) Then
i = i - 1
KeyOutput = "-" & KeyOutput
End If
Loop While i >= 0
ConvertToKey = KeyOutput
End Function
PowerShellとCMDは同意するVBSスクリプトは異なる値を示しています。
これはあるかもしれない理由を任意のアイデア?
UPDATE - ほぼそこそこ!
次のPowerShellスクリプトは、PowerShellコマンドとCmdコマンドと同じプロダクトキーを取得します。上記のスクリプトがhereから取られたが、考慮に入れた変更が示唆された
function Get-ProductKey {
<#
.SYNOPSIS
Retrieves the product key and OS information from a local or remote system/s.
.Description
Retrieves the product key and OS information from a local or remote system/s. Queries of 64bit OS from a 32bit OS will result in
inaccurate data being returned for the Product Key. You must query a 64bit OS from a system running a 64bit OS.
.Parameter ComputerName
Name of the local or remote system/s.
.Notes
Author: Boe Prox
Version: 1.1
-Update of function from http://powershell.com/cs/blogs/tips/archive/2012/04/30/getting-windows-product-key.aspx
-Added capability to query more than one system
-Supports remote system query
-Supports querying 64bit OSes
-Shows OS description and Version in output object
-Error Handling
.EXAMPLE
Get-ProductKey -Computername Server1
OSDescription Computername OSVersion ProductKey
------------- ------------ --------- ----------
Microsoft(R) Windows(R) Server 2003, Enterprise Edition Server1 5.2.3790 bcdfg-hjklm-pqrtt-vwxyy-12345
Description
-----------
Retrieves the product key information from 'Server1'
#>
[cmdletbinding()]
Param (
[parameter(ValueFromPipeLine=$True,ValueFromPipeLineByPropertyName=$True)]
[Alias("CN","__Server","IPAddress","Server")]
[string[]]$Computername = $Env:Computername
)
Begin {
$map="BCDFGHJKMPQRTVWXY2346789"
}
Process {
ForEach ($Computer in $Computername) {
Write-Verbose ("{0}: Checking network availability" -f $Computer)
If (Test-Connection -ComputerName $Computer -Count 1 -Quiet) {
Try {
Write-Verbose ("{0}: Retrieving WMI OS information" -f $Computer)
$OS = Get-WmiObject -ComputerName $Computer Win32_OperatingSystem -ErrorAction Stop
} Catch {
$OS = New-Object PSObject -Property @{
Caption = $_.Exception.Message
Version = $_.Exception.Message
}
}
Try {
Write-Verbose ("{0}: Attempting remote registry access" -f $Computer)
$remoteReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$Computer)
$value = $remoteReg.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('DigitalProductId')[0x34..0x42]
$isWin8OrNewer = [math]::Floor(($value[14]/6)) -band 1
$value[14] = ($value[14] -band 0xF7) -bor (($isWin8OrNewer -band 2) * 4)
$ProductKey = ""
Write-Verbose ("{0}: Translating data into product key" -f $Computer)
for ($i = 24; $i -ge 0; $i--) {
$r = 0
for ($j = 14; $j -ge 0; $j--) {
$r = ($r * 256) -bxor $value[$j]
$value[$j] = [math]::Floor([double]($r/24))
$r = $r % 24
}
$ProductKey = $map[$r] + $ProductKey
}
} Catch {
$ProductKey = $_.Exception.Message
}
if ($isWin8OrNewer){
$ProductKey = $ProductKey.Remove(0, 1)
$ProductKey = $ProductKey.Insert($r, 'N')
}
#insert dashes to make key more readable
for($i = 5; $i -lt 29; $i = $i + 6){
$ProductKey = $ProductKey.Insert($i, '-')
}
$object = New-Object PSObject -Property @{
Computername = $Computer
ProductKey = $ProductKey
OSDescription = $os.Caption
OSVersion = $os.Version
}
$object.pstypenames.insert(0,'ProductKey.Info')
$object
} Else {
$object = New-Object PSObject -Property @{
Computername = $Computer
ProductKey = 'Unreachable'
OSDescription = 'Unreachable'
OSVersion = 'Unreachable'
}
$object.pstypenames.insert(0,'ProductKey.Info')
$object
}
}
}
}
(私はその変更がまだ何であるかを確認する時間を持っていませんでした)何かが値が符号化されている方法で変更されたことが表示されます2016年2月5日付けのTJのコメントの中で、その人は伝説です!まあ、元の著者も、明らかに!
私が作成した時点でVB版を投稿します。この質問は閉鎖されないと仮定しています(投票が3つ必要ですので、すぐに行動してください)/ sarcasm。
両方のメソッドが異なる場所を使用してキーを見つけるためです。あなたは[これについて既に投稿しました](http://stackoverflow.com/q/39530254/692942)なぜ新しい質問を作成するのですか? – Lankymart
私は更新3:0を書きました)確かに、ウィンドウのコピーごとに1つのWindowsプロダクトキーしかないので、なぜ私が異なる回答を得ているのかについての私の混乱! VBSスクリプトは、過去に有効なWindowsプロダクトキーを取得していると賞賛されていませんでした。 –
それは明らかに別の質問です!ああ、あなたは今あなたが他の質問の著者だったことをあなたのコメントを変更しました。私の最初の質問は、プロダクトキーを取得することでしたが、この質問はなぜ私は別の結果を得るのですか? –