1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
Public Function sGetXPKey() As ListViewItem
'Registry öffnen und Wert auslesen (byte array)
Dim RegKey As RegistryKey = _
Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion", False)
Dim bytDPID() As Byte = RegKey.GetValue("DigitalProductID")
'Nur die benötigten Teile ins Array laden
' Key beginnt ab byte 52 und ist 15 Bytes lang.
Dim bytKey(14) As Byte '0-14 = 15 bytes
Array.Copy(bytDPID, 52, bytKey, 0, 15)
'Unser "Array" beinhaltet nun gültige Zeichen
Dim strChar As String = "BCDFGHJKMPQRTVWXY2346789"
'jetzt muss der decodierte Schlüssel zurückgegeben werden
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
'nun muss das Ganze in einen String eingestzt werden.
For i As Integer = 4 To 1 Step -1
strKey = strKey.Insert(i * 5, "-")
Next
Dim strPName As String = RegKey.GetValue("ProductName")
Dim strPID As String = RegKey.GetValue("ProductID")
Dim lvi As New ListViewItem
lvi.Text = strPName
Try
lvi.SubItems.Add(strKey)
Catch ex As Exception
lvi.SubItems.Add("n.a.")
End Try
Try
lvi.SubItems.Add(strPID)
Catch ex As Exception
lvi.SubItems.Add("n.a.")
End Try
RegKey.Close()
Return lvi
End Function
|