【发布时间】:2011-03-08 19:29:47
【问题描述】:
我正在使用此功能检索 Windows XP 许可证密钥,但它不适用于 Vista 和 Seven。如何获得这两个 Windows 版本的许可证密钥?
Public Function sGetXPKey() As String
Dim result As String = String.Empty
Dim RegKey As RegistryKey = _
Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion", False)
Dim bytDPID() As Byte = RegKey.GetValue("DigitalProductID")
Dim bytKey(14) As Byte
Array.Copy(bytDPID, 52, bytKey, 0, 15)
Dim strChar As String = "BCDFGHJKMPQRTVWXY2346789"
Dim strKey As String = ""
For j As Integer = 0 To 24
Dim nCur As Short = 0
For i As Integer = 14 To 0 Step -1
nCur = CShort(nCur * 256 Xor bytKey(i))
bytKey(i) = CByte(Int(nCur / 24))
nCur = CShort(nCur Mod 24)
Next
strKey = strChar.Substring(nCur, 1) & strKey
Next
For i As Integer = 4 To 1 Step -1
strKey = strKey.Insert(i * 5, "-")
Next
Return strKey
End Function
【问题讨论】:
-
为什么需要获取序列号?
-
我正在使用序列号的 md5 哈希为我的程序生成许可证密钥。
-
为什么不直接使用加密值的哈希值呢?还是在 Vista+ 上读取失败的密钥?
-
@Rowland Shaw:在 Windows 7 x64 上 bytDPID 为空 :)。我查看了注册表,还有一个 DigitalProductID4 键。但不确定是否会使用它。
-
但是,如果你只是在做一些独特的事情来做一个 MD5 散列,那就按原样使用它。
标签: windows vb.net windows-7 windows-vista license-key