簡體   English   中英

為XP,Vista和7獲取Windows串行

[英]Get windows serial for XP, Vista and Seven

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

建議您不要使用注冊表,而不要使用注冊表。 具體地, Win32_OperatingSystem如所描述的類這里 在該頁面上可以看到一個名為SerialNumber的屬性。

頁面包含有關如何執行此操作的完整示例(包括說明)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM