home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Software Sampler / Visual_Basic_Software_Sampler_Visual_Basic_Programmers_Journal_June_1996.iso / issues / 03mar96 / code / p22lst1.txt < prev    next >
Text File  |  1996-01-31  |  3KB  |  92 lines

  1. (c) 1996 VISUAL BASIC PROGRAMMER'S JOURNAL
  2. FAWCETTE TECHNICAL PUBLICATIONS
  3.  
  4. FILE NAME: KPMA96L.DOC ("Hacking the Registry")
  5. ISSUE: MARCH 96
  6. EDITOR: MC
  7. SECTION: FEATURES
  8.  
  9.  
  10. LISTINGS
  11. Listing 1: REGEDIT4 Script Generation
  12. Private Sub cmdScript_Click()
  13.     Dim CRLF As String
  14.     Dim QT As String
  15.     Dim sFile As String
  16.     For x = 1 To Len(txtFile) 'Double \\
  17.         If Mid$(txtFile, x, 1) = "\" Then sFile = sFile & "\"
  18.         sFile = sFile & Mid$(txtFile, x, 1)
  19.     Next x
  20.     CRLF = Chr$(13) & Chr$(10)
  21.     QT = Chr$(34)
  22.     txtScript = ""
  23.     txtScript = "REGEDIT4"
  24.     txtScript = txtScript & CRLF & "[HKEY_LOCAL_MACHINE\_
  25.         SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\_
  26.         FindExtensions\Static\" & txtShort & "]"
  27.     txtScript = txtScript & CRLF & "@=" & QT & txtGUID & QT
  28.     txtScript = txtScript & CRLF & "[HKEY_LOCAL_MACHINE\_
  29.         SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\_
  30.         FindExtensions\Static\" & txtShort & "\0]"
  31.     txtScript = txtScript & CRLF & "@=" & QT & txtDescription _
  32.         & QT
  33.     txtScript = txtScript & CRLF & "[HKEY_LOCAL_MACHINE\_
  34.         SOFTWARE\Microsoft\Windows\CurrentVersion\explorer\_
  35.         FindExtensions\Static\" & txtShort & "\0\DefaultIcon]"
  36.     txtScript = txtScript & CRLF & "@=" & QT & sFile & ",0" & QT
  37.     txtScript = txtScript & CRLF
  38.     txtScript = txtScript & CRLF & "[HKEY_CLASSES_ROOT\CLSID\" _
  39.         & txtGUID & "\FindCmd]"
  40.     txtScript = txtScript & CRLF & "@=" & QT & sFile & QT
  41.     txtScript = txtScript & CRLF & "[HKEY_CLASSES_ROOT\CLSID\" _
  42.         & txtGUID & "\InprocServer32]"
  43.     txtScript = txtScript & CRLF & "@=" & QT & "FindExt.dll" _
  44.         & QT
  45.     txtScript = txtScript & CRLF & QT & "ThreadingModel" & QT _
  46.         & "=" & QT & "Apartment" & QT
  47.     txtScript = txtScript & CRLF
  48.  
  49. LISTING 2.
  50. Declare Function RegNotifyChangeKeyValue Lib "advapi32.dll" _
  51.     (ByVal hKey As Long, ByVal bWatchSubtree As Long, ByVal _
  52.     dwNotifyFilter As Long, ByVal hEvent As Long, ByVal _
  53.     fAsynchronus As Long) As Long
  54. Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
  55.     hHandle As Long, ByVal dwMilliseconds As Long) As Long
  56. Declare Function CreateEvent Lib "kernel32" Alias _
  57.     "CreateEventA" (lpEventAttributes As Long, ByVal _
  58.     bManualReset As Long, ByVal bInitialState As Long, ByVal _
  59.     lpName As String) As Long
  60. Declare Function CloseHandle Lib "kernel32" (ByVal hObject As _
  61.     Long) As Long
  62. Public Const HKEY_CLASSES_ROOT = &H80000000
  63. Public Const REG_NOTIFY_CHANGE_ATTRIBUTES = &H2
  64. Public Const REG_NOTIFY_CHANGE_LAST_SET = &H4
  65. Public Const REG_NOTIFY_CHANGE_NAME = &H1
  66. Public Const REG_NOTIFY_CHANGE_SECURITY = &H8
  67.  
  68. Private Sub cmdRegistry_Click()
  69.     Dim lChange As Long
  70.     mhEvent = CreateEvent(0&, False, False, vbNullString)
  71.     lChange = RegNotifyChangeKeyValue(HKEY_CLASSES_ROOT, True, _
  72.         REG_NOTIFY_CHANGE_NAME, mhEvent, True)
  73.     tmrRegistry.Enabled = True
  74.     Me.Caption = "Waiting for registry change..."
  75.  
  76. End Sub
  77.  
  78. Private Sub tmrRegistry_Timer()
  79.     Static lSignal As Long
  80.     Static lResult As Long
  81.     
  82.     lSignal = WaitForSingleObject(mhEvent, 0&)
  83.     If lSignal = 0 Then
  84.         Me.Caption = "Registry Changed"
  85.         tmeRegistry.Enabled = False
  86.         lResult = CloseHandle(mhEvent)
  87.     End If
  88.         
  89. End Sub
  90.  
  91.  
  92.