PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/Visual Studio 2008/VBMonitorRegistryChange/Readme.txt

#
Plain Text | 53 lines | 40 code | 13 blank | 0 comment | 0 complexity | 148481b49f3cff25e23fa70ef9f53c90 MD5 | raw file
  1. ================================================================================
  2. Windows APPLICATION: VBMonitorRegistryChange Overview
  3. ===============================================================================
  4. /////////////////////////////////////////////////////////////////////////////
  5. Summary:
  6. The sample demonstrates how to monitor the registry key change event using WMI event.
  7. The change event will be raised when one of the following operations happened.
  8. 1 Rename or delete the key.
  9. 2 Add, rename or delete a sub key under the key.
  10. 3 Add, rename, edit or delete a value of the key.
  11. This WMI event does not return the changed value and type. It just tells that
  12. there is a change. The properties that you can get from the event are Hive, KeyPath,
  13. SECURITY_DESCRIPTOR and TIME_CREATED.
  14. ////////////////////////////////////////////////////////////////////////////////
  15. Demo:
  16. Step1. Build the sample project in Visual Studio 2008.
  17. Step2. Select a hive "HKEY_LOCAL_MACHINE" in the comboBox, and then type the key
  18. path "SOFTWARE\\Microsoft" in the textbox.
  19. Notice that you have to use double slash "\\" in the registry path.
  20. Step3. Click button "Start Monitor".
  21. Step4. Run "Regedit" in run command to open Registry Editor.
  22. Step5. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft in Registry Editor. Right click
  23. the key and create a new key. You'll see a new item
  24. "The key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft changed" in the list box.
  25. /////////////////////////////////////////////////////////////////////////////
  26. Code Logic:
  27. First, initialize the combobox cmbHives that contains all supported hives. Only
  28. HKEY_LOCAL_MACHINE, HKEY_USERS and HKEY_CURRENT_CONFIG are supported by RegistryEvent
  29. or classes derived from it, such as RegistryKeyChangeEvent.
  30. Second, when a user typed key path and clicked Start Monitor button, create a new instance
  31. of RegistryWatcher. The constructor of RegistryWatcher will check whether the key exists or
  32. the user has permission to access the key, then constructs a WqlEventQuery.
  33. Third, create a handler to listen for RegistryKeyChangeEvent of RegistryWatcher.
  34. At last, when an registry-change event arrived, displays the notification in a listbox.
  35. /////////////////////////////////////////////////////////////////////////////
  36. References:
  37. http://msdn.microsoft.com/en-us/library/aa393040(VS.85).aspx
  38. http://msdn.microsoft.com/en-us/library/aa392388(VS.85).aspx
  39. http://www.codeproject.com/KB/system/WMI_RegistryMonitor.aspx
  40. /////////////////////////////////////////////////////////////////////////////