获取XP,Vista和Seven的Windows系列

时间:2010-06-27 10:39:32

标签: windows vb.net windows-7 windows-vista license-key

我正在使用此功能检索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

1 个答案:

答案 0 :(得分:1)

我建议您使用WMI,而不是使用注册表。特别是Win32_OperatingSystem类,如here所述。从该页面可以看出,有一个名为SerialNumber的属性。

This页面包含有关如何操作的完整示例(包含说明)。