(c) 1996 VISUAL BASIC PROGRAMMER'S JOURNAL FAWCETTE TECHNICAL PUBLICATIONS FILE NAME: KPMA96L.DOC ("Hacking the Registry") ISSUE: MARCH 96 EDITOR: MC SECTION: FEATURES LISTINGS Listing 1: REGEDIT4 Script Generation Private Sub cmdScript_Click() Dim CRLF As String Dim QT As String Dim sFile As String For x = 1 To Len(txtFile) 'Double \\ If Mid$(txtFile, x, 1) = "\" Then sFile = sFile & "\" sFile = sFile & Mid$(txtFile, x, 1) Next x CRLF = Chr$(13) & Chr$(10) QT = Chr$(34) txtScript = "" txtScript = "REGEDIT4" txtScript = txtScript & CRLF & "[HKEY_LOCAL_MACHINE\_ SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\_ FindExtensions\Static\" & txtShort & "]" txtScript = txtScript & CRLF & "@=" & QT & txtGUID & QT txtScript = txtScript & CRLF & "[HKEY_LOCAL_MACHINE\_ SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\_ FindExtensions\Static\" & txtShort & "\0]" txtScript = txtScript & CRLF & "@=" & QT & txtDescription _ & QT txtScript = txtScript & CRLF & "[HKEY_LOCAL_MACHINE\_ SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\_ FindExtensions\Static\" & txtShort & "\0\DefaultIcon]" txtScript = txtScript & CRLF & "@=" & QT & sFile & ",0" & QT txtScript = txtScript & CRLF txtScript = txtScript & CRLF & "[HKEY_CLASSES_ROOT\CLSID\" _ & txtGUID & "\FindCmd]" txtScript = txtScript & CRLF & "@=" & QT & sFile & QT txtScript = txtScript & CRLF & "[HKEY_CLASSES_ROOT\CLSID\" _ & txtGUID & "\InprocServer32]" txtScript = txtScript & CRLF & "@=" & QT & "FindExt.dll" _ & QT txtScript = txtScript & CRLF & QT & "ThreadingModel" & QT _ & "=" & QT & "Apartment" & QT txtScript = txtScript & CRLF LISTING 2. Declare Function RegNotifyChangeKeyValue Lib "advapi32.dll" _ (ByVal hKey As Long, ByVal bWatchSubtree As Long, ByVal _ dwNotifyFilter As Long, ByVal hEvent As Long, ByVal _ fAsynchronus As Long) As Long Declare Function WaitForSingleObject Lib "kernel32" (ByVal _ hHandle As Long, ByVal dwMilliseconds As Long) As Long Declare Function CreateEvent Lib "kernel32" Alias _ "CreateEventA" (lpEventAttributes As Long, ByVal _ bManualReset As Long, ByVal bInitialState As Long, ByVal _ lpName As String) As Long Declare Function CloseHandle Lib "kernel32" (ByVal hObject As _ Long) As Long Public Const HKEY_CLASSES_ROOT = &H80000000 Public Const REG_NOTIFY_CHANGE_ATTRIBUTES = &H2 Public Const REG_NOTIFY_CHANGE_LAST_SET = &H4 Public Const REG_NOTIFY_CHANGE_NAME = &H1 Public Const REG_NOTIFY_CHANGE_SECURITY = &H8 Private Sub cmdRegistry_Click() Dim lChange As Long mhEvent = CreateEvent(0&, False, False, vbNullString) lChange = RegNotifyChangeKeyValue(HKEY_CLASSES_ROOT, True, _ REG_NOTIFY_CHANGE_NAME, mhEvent, True) tmrRegistry.Enabled = True Me.Caption = "Waiting for registry change..." End Sub Private Sub tmrRegistry_Timer() Static lSignal As Long Static lResult As Long lSignal = WaitForSingleObject(mhEvent, 0&) If lSignal = 0 Then Me.Caption = "Registry Changed" tmeRegistry.Enabled = False lResult = CloseHandle(mhEvent) End If End Sub