Share via


RegistryValueChangeEvent class

The RegistryValueChangeEvent class represents changes to a single value of a specific key. For more information about using the WMI registry event classes, see Modifying the System Registry. For code examples, see WMI Tasks: Registry.

The following syntax is simplified from Managed Object Format (MOF) code and includes all inherited properties. Properties and methods are in alphabetic order, not MOF order.

Syntax

class RegistryValueChangeEvent : RegistryEvent
{
  string Hive;
  string KeyPath;
  string ValueName;
};

Members

The RegistryValueChangeEvent class has these types of members:

Properties

The RegistryValueChangeEvent class has these properties.

Hive

Data type: string

Access type: Read-only

Name of the hive that contains the key (or keys) that is changed. For example, HKEY_LOCAL_MACHINE. Changes to the HKEY_CLASSES_ROOT and HKEY_CURRENT_USER hives are not supported by RegistryEvent or classes derived from it, such as RegistryValueChangeEvent.

KeyPath

Data type: string

Access type: Read-only

Path to the registry key. For example, "SOFTWARE\Microsoft\WBEM\Scripting".

ValueName

Data type: string

Access type: Read-only

Name of the value in the registry key. For example, in the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WBEM\Scripting you can detect changes in the value Default Namespace.

Remarks

Queries that provide a KeyPath must have backslashes escaped. For example,

wmiServices.ExecNotificationQuery("SELECT * FROM RegistryKeyChangeEvent " _
    & "WHERE Hive='HKEY_LOCAL_MACHINE' AND KeyPath='SOFTWARE\\Microsoft'")

Registry provider classes, unlike most of the Win32 classes are located in the WMI root\default namespace.

Examples

The following VBScript code example calls the asynchronous method SWbemServices_ExecNotificationQueryAsync to monitor changes in the registry value HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WBEM\Scripting\Default Namespace. Be aware that the backslashes in the registry key are escaped by a backslash ("\"). For more information about asynchronous calls and security, see Making an Asynchronous Call with VBScript. To see the operation of this script, execute the script and use a registry editor such as RegEdit to change the Default Namespace value. Be sure to change it back to the original value.

The following script runs until the computer is restarted, WMI is stopped, or the script is stopped. To stop the script manually, use Task Manager to stop the process. To stop it programmatically, use the Terminate method in the Win32_Process class.

Set wmiServices = GetObject("winmgmts:root/default") 
Set wmiSink = WScript.CreateObject("WbemScripting.SWbemSink", "SINK_") 
wmiServices.ExecNotificationQueryAsync wmiSink,"SELECT * FROM RegistryValueChangeEvent " _
    & "WHERE Hive='HKEY_LOCAL_MACHINE' AND KeyPath='SOFTWARE\\Microsoft\\WBEM\\Scripting' " _
    & "AND ValueName='Default Namespace'" 
WScript.Echo "Listening for Registry Value Change Events..." & vbCrLf 
While(True) 
    WScript.Sleep 1000 
Wend 
Sub SINK_OnObjectReady(wmiObject, wmiAsyncContext) 
    WScript.Echo "Received Registry Change Event" & vbCrLf & wmiObject.GetObjectText_() 
End Sub

Requirements

Minimum supported client
Windows Vista
Minimum supported server
Windows Server 2008
Namespace
Root\default
MOF
RegEvent.mof
DLL
StdProv.dll

See also

RegistryEvent

Registering for System Registry Events