Hallo an alle,
ausgangssituation:
Ich habe einen tollen button in visual basic 2008 den ich mit einen wert belegen möchte (den ich hier suche) der mir meinen cd key von windows ausliest. Ich habe diverse foren schon durch aber bin leider nie zum ergebniss gekommen.
Wisst ihr welchen wert ich den button zuordnen muss damit ich den windows key per popup oder in einen Label fenster anzeigen kann.
das habe ich bis jetzt...
Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion")
mhhh.. funtzt nurnet so richtig ^^ ...
vielen dank im vorraus..
Masterstrike
PS: wenn ihr noch andere lustige oder hilfreiche auslesecodes von daten habt nur her damit weil ich mir ein diagnistic tool schreibe.
Seite 1 von 1
Regestry Unter Vb 2008 Auslesen
Anzeige
#3
geschrieben 08. Dezember 2008 - 13:55
Registry.LocalMachine.OpenSubKey() gibt dir ein Objekt vom Typ RegistryKey zurueck, dieser enthaelt mehrere Werte. Diese kannst du mit GetValue() auslesen.
Fuer den Produktschluessel kannst du diese Funktion benutzen
Anzuwenden mit
Label1.Text = readKey()
Fuer andere Informationen kannst du dir die Environment und OperatingSystem Klassen anschauen.
Fuer den Produktschluessel kannst du diese Funktion benutzen
CODE
'http://www.devasp.net/net/articles/display/406.html
Public Function readKey() As String
Dim RegKey As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion")
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
Public Function readKey() As String
Dim RegKey As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion")
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
Anzuwenden mit
Label1.Text = readKey()
Fuer andere Informationen kannst du dir die Environment und OperatingSystem Klassen anschauen.
#4
geschrieben 08. Dezember 2008 - 19:05
hi,
@aeris
Vielen dank für deine antwort ic versuchs mal und werde dann über Sieg oder niederlage berichten ^^
wer intresse hat: Ich kann das Progg mal reinstellen.
LG Masterstrike
@aeris
Vielen dank für deine antwort ic versuchs mal und werde dann über Sieg oder niederlage berichten ^^
wer intresse hat: Ich kann das Progg mal reinstellen.
LG Masterstrike
#5
geschrieben 08. Dezember 2008 - 19:21
habe doch noch ein kleine Prob mit der ausgabe des keys. (denke ich) label11 ist mein ausgabefeld.
kannst du mir da villt noch helfen ?
LG MAsterstrike
kannst du mir da villt noch helfen ?
CODE
Public Function GetXPKey() As String
Dim RegKey As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion")
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
Label11.Text = strKey
End Function
End Class
Dim RegKey As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion")
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
Label11.Text = strKey
End Function
End Class
LG MAsterstrike
#6
geschrieben 08. Dezember 2008 - 22:32
Huhu,
Stelle sicher, dass du oben
Imports Microsoft.Win32
stehen hast.
Auszerdem kannst du nach einem Return keine Anweisungen geben, da dort der Ablauf sozusagen Beendet wird.
Ein Beispiel wie so etwas zu benutzen ist:
Du hast deine Funktion fuer Button Click (oder Aehnliches)
darunter (oder darueber, egal) kommt der Rest:
Falls du das ganze ohne eigene Funktion haben willst, kannst du das return loeschen und einfach deinem Label zuweisen:
Vorteil beim ersten ist, du kannst die Funktion so oft aufrufen wie du willst, ohne staendig den selben Code neu zu schreiben.
Hier nochmal alles zusammen: http://pastebin.com/m7c156569
Stelle sicher, dass du oben
Imports Microsoft.Win32
stehen hast.
Auszerdem kannst du nach einem Return keine Anweisungen geben, da dort der Ablauf sozusagen Beendet wird.
Ein Beispiel wie so etwas zu benutzen ist:
Du hast deine Funktion fuer Button Click (oder Aehnliches)
CODE
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label11.Text = GetXPKey()
End Sub
Label11.Text = GetXPKey()
End Sub
darunter (oder darueber, egal) kommt der Rest:
CODE
Public Function GetXPKey() As String
Dim RegKey As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion")
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
Dim RegKey As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion")
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
Falls du das ganze ohne eigene Funktion haben willst, kannst du das return loeschen und einfach deinem Label zuweisen:
CODE
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim RegKey As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion")
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
Label1.Text = strKey
End Sub
Dim RegKey As RegistryKey = Registry.LocalMachine.OpenSubKey("Software\Microsoft\Windows NT\CurrentVersion")
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
Label1.Text = strKey
End Sub
Vorteil beim ersten ist, du kannst die Funktion so oft aufrufen wie du willst, ohne staendig den selben Code neu zu schreiben.
Hier nochmal alles zusammen: http://pastebin.com/m7c156569
Thema verteilen:
Seite 1 von 1