Windows Key auslesen unter C#?

2 Antworten


Vor langer Zeit hatte ich mal solchen Code geschrieben:

Public Enum MicrosoftProduct
Office
Windows
End Enum

Public Function GetProductKey(ByVal Product As MicrosoftProduct) As String
Dim RegKey As RegistryKey
Dim DigitalPID() As Byte
Dim Key(14) As Byte
Dim strChar As String = "BCDFGHJKMPQRTVWXY2346789"
Dim strKey As String = ""
Dim nCur As Short = 0

If Product = MicrosoftProduct.Windows Then
RegKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion", False)
Else
RegKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Office\11.0\Registration\{90110407-6000-11D3-8CFE-0150048383C9}", False)
End If

DigitalPID = RegKey.GetValue("DigitalProductID")
Array.Copy(DigitalPID, 52, Key, 0, 15)

For j As Integer = 0 To 24
nCur = 0
For i As Integer = 14 To 0 Step -1
nCur = CShort(nCur * 256 Xor Key(i))
Key(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

Der Code ist allerdings alles andere als schön.  Das hatte ich damals sehr lieblos programmiert, sollte aber funktionieren.