質問

この機能で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
役に立ちましたか?

解決

レジストリを使用するのではなく、WMIを使用することをお勧めします。具体的には Win32_OperatingSystem 説明されているクラス ここ. 。そのページにわかるように、呼ばれるプロパティがあります SerialNumber.

これ ページには、それを行う方法に関する完全なサンプル(説明付き)が含まれています。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top