Interritor
Erfahrenes Mitglied
Wie gesagt das ist net so leicht!
Hier der Code:
Option Explicit
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" _
Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal _
lpSubKey As String, ByVal ulOptions As Long, ByVal _
samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" _
Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal _
lpValueName As String, ByVal lpReserved As Long, _
lpType As Long, lpData As Any, lpcbData As Any) As Long
Private Declare Function RegCreateKeyEx Lib "advapi32.dll" _
Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal _
lpSubKey As String, ByVal Reserved As Long, ByVal _
lpClass As String, ByVal dwOptions As Long, ByVal _
samDesired As Long, ByVal lpSecurityAttributes As Any, _
phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegFlushKey Lib "advapi32.dll" (ByVal _
hKey As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" _
Alias "RegSetValueExA" (ByVal hKey As Long, ByVal _
lpValueName As String, ByVal Reserved As Long, ByVal _
dwType As Long, lpData As Long, ByVal cbData As Long) _
As Long
Private Declare Function RegSetValueEx_Str Lib "advapi32.dll" _
Alias "RegSetValueExA" (ByVal hKey As Long, ByVal _
lpValueName As String, ByVal Reserved As Long, ByVal _
dwType As Long, ByVal lpData As String, ByVal cbData As _
Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll"Alias _
"RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As _
String) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll"Alias _
"RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName _
As String) As Long
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_PERFORMANCE_DATA = &H80000004
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_DYN_DATA = &H80000006
Const KEY_QUERY_VALUE = &H1
Const KEY_SET_VALUE = &H2
Const KEY_CREATE_SUB_KEY = &H4
Const KEY_ENUMERATE_SUB_KEYS = &H8
Const KEY_NOTIFY = &H10
Const KEY_CREATE_LINK = &H20
Const KEY_READ = KEY_QUERY_VALUE Or _
KEY_ENUMERATE_SUB_KEYS _
Or KEY_NOTIFY
Const KEY_ALL_ACCESS = KEY_QUERY_VALUE Or _
KEY_SET_VALUE Or _
KEY_CREATE_SUB_KEY Or _
KEY_ENUMERATE_SUB_KEYS Or _
KEY_NOTIFY Or _
KEY_CREATE_LINK
Const ERROR_SUCCESS = 0&
Const REG_NONE = 0
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_DWORD_LITTLE_ENDIAN = 4
Const REG_DWORD_BIG_ENDIAN = 5
Const REG_LINK = 6
Const REG_MULTI_SZ = 7
Const REG_OPTION_NON_VOLATILE = &H0
Private RegRoot&
Private Sub Command8_Click()
Call Shell("regedit.exe", vbNormalFocus)
End Sub
Private Sub Form_Load()
'Voreinstellungen eintragen
Text1.Text = "Test-Ordner"
Text2.Text = "Test-Ordner"
Text3.Text = "Test-Ordner"
Text4.Text = "Wert-Long"
Text5.Text = "12345"
Text6.Text = "Test-Ordner"
Text7.Text = "Wert-String"
Text8.Text = "Hallo"
Text9.Text = "Test-Ordner"
Text10.Text = "Wert-Long"
Text11.Text = "Test-Ordner"
Text12.Text = "Wert-String"
Text13.Text = "Test-Ordner"
Text14.Text = "Wert-Long"
Text15.Text = "Test-Ordner"
Text16.Text = "Wert-String"
Text17.Text = "Test-Ordner"
List1.AddItem "HKEY_CLASSES_ROOT"
List1.ItemData(0) = HKEY_CLASSES_ROOT
List1.AddItem "HKEY_CURRENT_USER"
List1.ItemData(1) = HKEY_CURRENT_USER
List1.AddItem "HKEY_LOCAL_MACHINE"
List1.ItemData(2) = HKEY_LOCAL_MACHINE
List1.AddItem "HKEY_USERS"
List1.ItemData(3) = HKEY_USERS
List1.AddItem "HKEY_PERFORMANCE_DATA"
List1.ItemData(4) = HKEY_PERFORMANCE_DATA
List1.AddItem "HKEY_CURRENT_CONFIG"
List1.ItemData(5) = HKEY_CURRENT_CONFIG
List1.AddItem "HKEY_DYN_DATA"
List1.ItemData(6) = HKEY_DYN_DATA
List1.ListIndex = 2
End Sub
Private Sub List1_Click()
'Bei Klick Hauptverzeichnis wechseln
Frame6.Caption = List1.List(List1.ListIndex)
RegRoot = List1.ItemData(List1.ListIndex)
End Sub
Private Sub Command1_Click()
Dim Result&
'Schlüssel erstellen
Result = RegKeyCreate(RegRoot, Text1.Text)
Select Case Result
Case 0: Label5.Caption = "Fehler beim Erstellen"
Case 1: Label5.Caption = "Ok, Pfad neu erstellt"
Case 2: Label5.Caption = "Ok, Pfad existierte schon"
End Select
End Sub
Private Sub Command2_Click()
Dim Result&
'Testen ob Schlüssel existiert
Result = RegKeyExist(RegRoot, Text2.Text)
If Result = 0 Then
Label6.Caption = "vorhanden"
Else
Label6.Caption = "nicht vorhanden"
End If
End Sub
Private Sub Command3_Click()
Dim Result&, LngInt&
'Longwert ein ein Feld schreiben
LngInt = CLng(Val(Text5.Text))
Result = RegValueSet(RegRoot, Text3.Text, Text4.Text, LngInt)
If Result = 0 Then
Label7.Caption = "Ok"
Else
Label7.Caption = "Fehler"
End If
End Sub
Hier der Code:
Option Explicit
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" _
Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal _
lpSubKey As String, ByVal ulOptions As Long, ByVal _
samDesired As Long, phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" _
Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal _
lpValueName As String, ByVal lpReserved As Long, _
lpType As Long, lpData As Any, lpcbData As Any) As Long
Private Declare Function RegCreateKeyEx Lib "advapi32.dll" _
Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal _
lpSubKey As String, ByVal Reserved As Long, ByVal _
lpClass As String, ByVal dwOptions As Long, ByVal _
samDesired As Long, ByVal lpSecurityAttributes As Any, _
phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegFlushKey Lib "advapi32.dll" (ByVal _
hKey As Long) As Long
Private Declare Function RegSetValueEx Lib "advapi32.dll" _
Alias "RegSetValueExA" (ByVal hKey As Long, ByVal _
lpValueName As String, ByVal Reserved As Long, ByVal _
dwType As Long, lpData As Long, ByVal cbData As Long) _
As Long
Private Declare Function RegSetValueEx_Str Lib "advapi32.dll" _
Alias "RegSetValueExA" (ByVal hKey As Long, ByVal _
lpValueName As String, ByVal Reserved As Long, ByVal _
dwType As Long, ByVal lpData As String, ByVal cbData As _
Long) As Long
Private Declare Function RegDeleteKey Lib "advapi32.dll"Alias _
"RegDeleteKeyA" (ByVal hKey As Long, ByVal lpSubKey As _
String) As Long
Private Declare Function RegDeleteValue Lib "advapi32.dll"Alias _
"RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName _
As String) As Long
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_PERFORMANCE_DATA = &H80000004
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_DYN_DATA = &H80000006
Const KEY_QUERY_VALUE = &H1
Const KEY_SET_VALUE = &H2
Const KEY_CREATE_SUB_KEY = &H4
Const KEY_ENUMERATE_SUB_KEYS = &H8
Const KEY_NOTIFY = &H10
Const KEY_CREATE_LINK = &H20
Const KEY_READ = KEY_QUERY_VALUE Or _
KEY_ENUMERATE_SUB_KEYS _
Or KEY_NOTIFY
Const KEY_ALL_ACCESS = KEY_QUERY_VALUE Or _
KEY_SET_VALUE Or _
KEY_CREATE_SUB_KEY Or _
KEY_ENUMERATE_SUB_KEYS Or _
KEY_NOTIFY Or _
KEY_CREATE_LINK
Const ERROR_SUCCESS = 0&
Const REG_NONE = 0
Const REG_SZ = 1
Const REG_EXPAND_SZ = 2
Const REG_BINARY = 3
Const REG_DWORD = 4
Const REG_DWORD_LITTLE_ENDIAN = 4
Const REG_DWORD_BIG_ENDIAN = 5
Const REG_LINK = 6
Const REG_MULTI_SZ = 7
Const REG_OPTION_NON_VOLATILE = &H0
Private RegRoot&
Private Sub Command8_Click()
Call Shell("regedit.exe", vbNormalFocus)
End Sub
Private Sub Form_Load()
'Voreinstellungen eintragen
Text1.Text = "Test-Ordner"
Text2.Text = "Test-Ordner"
Text3.Text = "Test-Ordner"
Text4.Text = "Wert-Long"
Text5.Text = "12345"
Text6.Text = "Test-Ordner"
Text7.Text = "Wert-String"
Text8.Text = "Hallo"
Text9.Text = "Test-Ordner"
Text10.Text = "Wert-Long"
Text11.Text = "Test-Ordner"
Text12.Text = "Wert-String"
Text13.Text = "Test-Ordner"
Text14.Text = "Wert-Long"
Text15.Text = "Test-Ordner"
Text16.Text = "Wert-String"
Text17.Text = "Test-Ordner"
List1.AddItem "HKEY_CLASSES_ROOT"
List1.ItemData(0) = HKEY_CLASSES_ROOT
List1.AddItem "HKEY_CURRENT_USER"
List1.ItemData(1) = HKEY_CURRENT_USER
List1.AddItem "HKEY_LOCAL_MACHINE"
List1.ItemData(2) = HKEY_LOCAL_MACHINE
List1.AddItem "HKEY_USERS"
List1.ItemData(3) = HKEY_USERS
List1.AddItem "HKEY_PERFORMANCE_DATA"
List1.ItemData(4) = HKEY_PERFORMANCE_DATA
List1.AddItem "HKEY_CURRENT_CONFIG"
List1.ItemData(5) = HKEY_CURRENT_CONFIG
List1.AddItem "HKEY_DYN_DATA"
List1.ItemData(6) = HKEY_DYN_DATA
List1.ListIndex = 2
End Sub
Private Sub List1_Click()
'Bei Klick Hauptverzeichnis wechseln
Frame6.Caption = List1.List(List1.ListIndex)
RegRoot = List1.ItemData(List1.ListIndex)
End Sub
Private Sub Command1_Click()
Dim Result&
'Schlüssel erstellen
Result = RegKeyCreate(RegRoot, Text1.Text)
Select Case Result
Case 0: Label5.Caption = "Fehler beim Erstellen"
Case 1: Label5.Caption = "Ok, Pfad neu erstellt"
Case 2: Label5.Caption = "Ok, Pfad existierte schon"
End Select
End Sub
Private Sub Command2_Click()
Dim Result&
'Testen ob Schlüssel existiert
Result = RegKeyExist(RegRoot, Text2.Text)
If Result = 0 Then
Label6.Caption = "vorhanden"
Else
Label6.Caption = "nicht vorhanden"
End If
End Sub
Private Sub Command3_Click()
Dim Result&, LngInt&
'Longwert ein ein Feld schreiben
LngInt = CLng(Val(Text5.Text))
Result = RegValueSet(RegRoot, Text3.Text, Text4.Text, LngInt)
If Result = 0 Then
Label7.Caption = "Ok"
Else
Label7.Caption = "Fehler"
End If
End Sub