Вот, у меня примерчик какой то завалялся: На форме Label1 Command1 Private Sub Command1_Click() Dim cap As String sChange = "" cap = Caption Caption = "Monitoring..." Label1 = "Try to change HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Registry Notification\Hello\Testing" Label1 = Label1 & vbCrLf & "or any other key under HKCU\Software\VB and VBA Program Settings with RegEdit" Call RegMonitor(HKEY_CURRENT_USER, "Software\VB and VBA Program Settings", True, REG_NOTIFY_CHANGE_ATTRIBUTES + REG_NOTIFY_CHANGE_LAST_SET + REG_NOTIFY_CHANGE_NAME + REG_NOTIFY_CHANGE_SECURITY) ' Try to change this key or any other under HKCU Label1 = "Your key have been changed!!!" Label1 = Label1 & vbCrLf & "Press command button to start monitoring. (Your App will freeze while monitoring)" Caption = cap End Sub Private Sub Form_Load() Label1 = "Application created a temporary registry key:" Label1 = Label1 & vbCrLf & "HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Registry Notification\Hello\Testing" Label1 = Label1 & vbCrLf & "Press command button to start monitoring. (Your App will freeze while monitoring)" 'Create a temporary registry key SaveSetting "Registry Notification", "Hello", "Testing", "123" End Sub 'modul: 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 = &H1 REG_NOTIFY_CHANGE_ATTRIBUTES = &H2 REG_NOTIFY_CHANGE_LAST_SET = &H4 REG_NOTIFY_CHANGE_SECURITY = &H8 End Enum Private Declare Function RegNotifyChangeKeyValue Lib "advapi32" (ByVal hKey As Long, ByVal bWatchSubTree As Boolean, ByVal dwNotifyFilter As Long, ByVal hEvent As Long, ByVal fAsynchronous As Boolean) As Long Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long Public Sub RegMonitor(hKey As ROOT_KEYS, sRegKeyPath As String, bWatchSubTree As Boolean, dwFilters As NOTIFY_EVENTS) Dim lKeyHandle As Long, lRet As Long lRet = RegOpenKey(hKey, sRegKeyPath, lKeyHandle) RegNotifyChangeKeyValue lKeyHandle, bWatchSubTree, dwFilters, 0&, False lRet = RegCloseKey(lKeyHandle) End Sub
Ответить
|