VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code allows you to create keys, delete keys and delete values from the registry

by INVICTUS (2 Submissions)
Category: Registry
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 26th August 2005
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This code allows you to create keys, delete keys and delete values from the registry

API Declarations


textboxes: txtclass, txtkey

Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult 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

Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_CURRENT_CONFIG = &H80000005
Private Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_USERS = &H80000003
Private Const REG_SZ = 1



Rate This code allows you to create keys, delete keys and delete values from the registry



Dim r As Long
If txtclass.Text = "HKEY_LOCAL_MACHINE" Then
r = RegCreateKey(HKEY_LOCAL_MACHINE, txtkey.Text, REG_SZ)
Else
    If txtclass.Text = "HKEY_CURRENT_USER" Then
r = RegCreateKey(HKEY_CURRENT_USER, txtkey.Text, REG_SZ)
Else
        If txtclass.Text = "HKEY_CURRENT_CONFIG" Then
r = RegCreateKey(HKEY_CURRENT_CONFIG, txtkey.Text, REG_SZ)
Else
            If txtclass.Text = "HKEY_CLASSES_ROOT" Then
r = RegCreateKey(HKEY_CLASSES_ROOT, txtkey.Text, REG_SZ)
Else
                If txtclass.Text = "HKEY_USERS" Then
r = RegCreateKey(HKEY_USERS, txtkey.Text, REG_SZ)
Else
MsgBox "Not a valid class", vbCritical
End If
 End If
  End If
   End If
    End If
     
End Sub

Private Sub cmddeletevalue_Click()
Dim r As Long
If txtclass.Text = "HKEY_LOCAL_MACHINE" Then
r = RegDeleteValue(HKEY_LOCAL_MACHINE, txtkey.Text)
Else
    If txtclass.Text = "HKEY_CURRENT_USER" Then
r = RegDeleteValue(HKEY_CURRENT_USER, txtkey.Text)
Else
        If txtclass.Text = "HKEY_CURRENT_CONFIG" Then
r = RegDeleteValue(HKEY_CURRENT_CONFIG, txtkey.Text)
Else
            If txtclass.Text = "HKEY_CLASSES_ROOT" Then
r = RegDeleteValue(HKEY_CLASSES_ROOT, txtkey.Text)
Else
                If txtclass.Text = "HKEY_USERS" Then
r = RegDeleteValue(HKEY_USERS, txtkey.Text)
Else
MsgBox "Not a valid class", vbCritical
End If
 End If
  End If
   End If
    End If
     
End Sub

Private Sub cmddeletekey_Click()
If txtclass.Text = "HKEY_LOCAL_MACHINE" Then
Call RegDeleteKey(HKEY_LOCAL_MACHINE, txtkey.Text)
Else
    If txtclass.Text = "HKEY_CURRENT_USER" Then
Call RegDeleteKey(HKEY_CURRENT_USER, txtkey.Text)
Else
        If txtclass.Text = "HKEY_CURRENT_CONFIG" Then
Call RegDeleteKey(HKEY_CURRENT_CONFIG, txtkey.Text)
Else
            If txtclass.Text = "HKEY_CLASSES_ROOT" Then
Call RegDeleteKey(HKEY_CLASSES_ROOT, txtkey.Text)
Else
                If txtclass.Text = "HKEY_USERS" Then
Call RegDeleteKey(HKEY_USERS, txtkey.Text)
Else
MsgBox "Not a valid class", vbCritical
End If
 End If
  End If
   End If
    End If
     
End Sub


Download this snippet    Add to My Saved Code

This code allows you to create keys, delete keys and delete values from the registry Comments

No comments have been posted about This code allows you to create keys, delete keys and delete values from the registry. Why not be the first to post a comment about This code allows you to create keys, delete keys and delete values from the registry.

Post your comment

Subject:
Message:
0/1000 characters