获取 XP、Vista 和 7 的 Windows 序列号
我正在使用此功能检索 Windows XP 许可证密钥,但它不适用于 Vista 和 7。如何获取这两个 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您不要使用注册表,而应该使用 WMI。具体来说,Win32_OperatingSystem 类>这里。从该页面可以看出,有一个名为
SerialNumber
的属性。此页面包含有关如何操作的完整示例(带有说明)它。
Rather than using the registry I'd suggest that you should use WMI. Specifically the
Win32_OperatingSystem
class as described here. As can be seen on that page there is a property calledSerialNumber
.This page contains a complete sample (with explanations) for how to do it.