Try
Dim query As New WqlEventQuery( _
"SELECT * FROM RegistryValueChangeEvent WHERE " & _
"KeyPath = 'HKEY_LOCAL_MACHINE\SOFTWARE\7-Zip'" & _
" AND ValueName = 'Path'")
Dim watcher As New ManagementEventWatcher(query)
'Console.WriteLine("Waiting for an event...")
Dim eventObj As ManagementBaseObject = watcher.WaitForNextEvent()
Console.WriteLine("{0} event occurred.", eventObj("__CLASS"))
' Cancel the event subscription
watcher.Stop()
Catch err As ManagementException
MessageBox.Show("An error occurred while trying to receive an event: " & err.Message)
End Try
|