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