[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Management
[/SIZE][SIZE=2][COLOR=#0000ff]Module[/COLOR][/SIZE][SIZE=2] Module1[/SIZE]
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] main()[/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] watcher1 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] ManagementEventWatcher
watcher1 = GetWatcher([/SIZE][SIZE=2][COLOR=#800000]"__InstanceCreationEvent"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"Win32_Process"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff] AddHandler[/COLOR][/SIZE][SIZE=2] watcher1.EventArrived, [/SIZE][SIZE=2][COLOR=#0000ff]AddressOf[/COLOR][/SIZE][SIZE=2] Win32ProcArrived
watcher1.Start()
[/SIZE][SIZE=2][COLOR=#008000] '
[/COLOR][/SIZE][SIZE=2] Console.WriteLine([/SIZE][SIZE=2][COLOR=#800000]"press <enter> to stop..."[/COLOR][/SIZE][SIZE=2])
Console.ReadLine()
watcher1.Stop()
[/SIZE][SIZE=2][COLOR=#0000ff] RemoveHandler[/COLOR][/SIZE][SIZE=2] watcher1.EventArrived, [/SIZE][SIZE=2][COLOR=#0000ff]AddressOf[/COLOR][/SIZE][SIZE=2] Win32ProcArrived
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] GetWatcher([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] WatcherType [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] wmiclass [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] ManagementEventWatcher
[/SIZE][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] condition [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"TargetInstance ISA '"[/COLOR][/SIZE][SIZE=2] & wmiclass & [/SIZE][SIZE=2][COLOR=#800000]"'"
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] EventQuery [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] WqlEventQuery(WatcherType, [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] TimeSpan(0, 0, 3), condition)
[/SIZE][SIZE=2][COLOR=#0000ff] Return [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] ManagementEventWatcher(EventQuery)
[/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Win32ProcArrived([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] EventArrivedEventArgs)
[/SIZE][SIZE=2][COLOR=#0000ff]For [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] pd [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] PropertyData [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] e.NewEvent.Properties
[/SIZE][SIZE=2][COLOR=#0000ff] Dim[/COLOR][/SIZE][SIZE=2] mbo [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] ManagementBaseObject = [/SIZE][SIZE=2][COLOR=#0000ff]DirectCast[/COLOR][/SIZE][SIZE=2](pd.Value, ManagementBaseObject)
[/SIZE][SIZE=2][COLOR=#0000ff] If [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Not[/COLOR][/SIZE][SIZE=2] mbo [/SIZE][SIZE=2][COLOR=#0000ff]Is [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Nothing [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2] Console.WriteLine([/SIZE][SIZE=2][COLOR=#800000]"--------------Process Properties------------------"[/COLOR][/SIZE][SIZE=2])
Console.WriteLine([/SIZE][SIZE=2][COLOR=#800000]"{0} - {1}"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"Caption"[/COLOR][/SIZE][SIZE=2], mbo([/SIZE][SIZE=2][COLOR=#800000]"Caption"[/COLOR][/SIZE][SIZE=2]).ToString)
Console.WriteLine([/SIZE][SIZE=2][COLOR=#800000]"{0} - {1}"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"CommandLine"[/COLOR][/SIZE][SIZE=2], mbo([/SIZE][SIZE=2][COLOR=#800000]"CommandLine"[/COLOR][/SIZE][SIZE=2]).ToString)
Console.WriteLine([/SIZE][SIZE=2][COLOR=#800000]"{0} - {1}"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"ExecutablePath"[/COLOR][/SIZE][SIZE=2], mbo([/SIZE][SIZE=2][COLOR=#800000]"ExecutablePath"[/COLOR][/SIZE][SIZE=2]).ToString)
Console.WriteLine([/SIZE][SIZE=2][COLOR=#800000]"{0} - {1}"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"ProcessId"[/COLOR][/SIZE][SIZE=2], mbo([/SIZE][SIZE=2][COLOR=#800000]"ProcessId"[/COLOR][/SIZE][SIZE=2]).ToString)
[/SIZE][SIZE=2][COLOR=#008000] ' to have a look at all properties use this:
[/COLOR][/SIZE][SIZE=2][COLOR=#008000] 'For Each prop As PropertyData In mbo.Properties
[/COLOR][/SIZE][SIZE=2][COLOR=#008000] 'Console.WriteLine("{0} - {1}", prop.Name, prop.Value)
[/COLOR][/SIZE][SIZE=2][COLOR=#008000] 'Next
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff] End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Module
[/COLOR][/SIZE]