Registry Monitoring

pitaridis

Well-known member
Joined
Nov 18, 2005
Messages
63
Programming Experience
10+
I am trying to write an application which will monitor the registry. I found the following code but when I run the script the application does not respond. Can someone tell me what is wrong with this script?

Public Enum ROOT_KEYS
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_USER = &H80000001
HKEY_LOCAL_MACHINE = &H80000002
HKEY_USERS = &H80000003
HKEY_PERFORMANCE_DATA = &H80000004
HKEY_CURRENT_CONFIG = &H80000005
HKEY_DYN_DATA = &H80000006
End Enum

Public Enum NOTIFY_EVENTS
REG_NOTIFY_CHANGE_NAME = &H1s
REG_NOTIFY_CHANGE_ATTRIBUTES = &H2s
REG_NOTIFY_CHANGE_LAST_SET = &H4s
REG_NOTIFY_CHANGE_SECURITY = &H8s
End Enum

Private Declare Function RegNotifyChangeKeyValue Lib "advapi32" (ByVal hKey As Integer, ByVal bWatchSubTree As Boolean, ByVal dwNotifyFilter As Integer, ByVal hEvent As Integer, ByVal fAsynchronous As Boolean) As Integer
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA"(ByVal hKey As Integer, ByVal lpSubKey As String, ByRef phkResult As Integer) As Integer
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Integer) As Integer

Public Sub RegMonitor(ByRef hKey As ROOT_KEYS, ByRef sRegKeyPath As String, ByRef bWatchSubTree As Boolean, ByRef dwFilters As NOTIFY_EVENTS)
Dim lKeyHandle, lRet As Integer
lRet = RegOpenKey(hKey, sRegKeyPath, lKeyHandle)
RegNotifyChangeKeyValue(lKeyHandle, bWatchSubTree, dwFilters, 0,
False)
lRet = RegCloseKey(lKeyHandle)
End Sub

Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
RegMonitor(ROOT_KEYS.HKEY_CURRENT_USER,
"Software\VB and VBA Program Settings", True, NOTIFY_EVENTS.REG_NOTIFY_CHANGE_ATTRIBUTES + NOTIFY_EVENTS.REG_NOTIFY_CHANGE_LAST_SET + NOTIFY_EVENTS.REG_NOTIFY_CHANGE_NAME + NOTIFY_EVENTS.REG_NOTIFY_CHANGE_SECURITY)
End Sub
 
Did you want to send something because I can not find any useful information?
 
Back
Top