VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Removing a registry entry

by Dean lancaster (2 Submissions)
Category: Files/File Controls/Input/Output
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

After you have read my tutorial on adding a registry entry no doubt now you will want to be able to remove it as well.

Rate Removing a registry entry

Ok i assume you read my article on how to create a registry entry, if not search in the top search link for "auto run registry entry" and you should find it.

This is how to remove a registry entry from the registry.


Some where in your project you will need to insert the following code.



Call DeleteStringValue(HKEY_LOCAL_MACHINE, "Software\microsoft\windows\currentversion\run", "currency")


After this has been inserted into your code goto your module form in your project and enter the following code.




Public Exist As Boolean
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const ERROR_SUCCESS = 0&
Public Const REG_SZ = 1
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal Hkey As Long, ByVal lpValueName As String) As Long
Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal Hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
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 Long) As Long
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 Any, ByVal cbData As Long) As Long


After that has been inserted place this code into your program listing and you should be able to delete registry entries




Public Sub DeleteStringValue(Hkey As Long, strPath As String, strValue As String)
Dim keyhand As Long
Dim i As Long
  'Open the key
  i = RegOpenKey(Hkey, strPath, keyhand)
  'Delete the value
  i = RegDeleteValue(keyhand, strValue)
  'Close the key
  i = RegCloseKey(keyhand)
End Sub


Remember that in the code 

HKEY_LOCAL_MACHINE, "Software\microsoft\windows\currentversion\run", "currency")


The item, "hkey_local_machine" can be changed to any root inside the registry.


"software\microsoft\windows\currentversion\run" can be any point inside the root directory you have specified.


"currency" Is tha name of the registry entry that you are putting into the registry, change it to something that is of meaning to your program and should exist inside the registry already (in other words you have created it using the method I told you about on creating registry entries in an earlier tutorial.


As always if you need help with anything mail me and i will help you as best i can.


Thanks Dean.

Download this snippet    Add to My Saved Code

Removing a registry entry Comments

No comments have been posted about Removing a registry entry. Why not be the first to post a comment about Removing a registry entry.

Post your comment

Subject:
Message:
0/1000 characters