Detecting process start

N

Niclas

Hi,

I am trying to fire an event when a certain process starts, but can't get
the event to fire. Would appreciate if someone could validate the code below
for any obvious errors.
I was hoping this code would write an entry to my eventlog when every new
process start (as a test)

Public Class myClass

Private WithEvents ProcessWatch As ManagementEventWatcher

'Service OnStart Event launches StartProcessWatcher here

Private Sub StartProcessWatcher()

Dim wmiQuery As WqlEventQuery
wmiQuery = New WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace")
ProcessWatch = New ManagementEventWatcher(wmiQuery)
AddHandler ProcessWatch.EventArrived, AddressOf Process_EventArrived
ProcessWatch.Start()
End Sub

Private Sub Logon_EventArrived(ByVal sender As Object, ByVal e As
System.Management.EventArrivedEventArgs)

WriteToLog(e.NewEvent.Properties("ProcessName").Value.ToString,
EventLogEntryType.Error)
'Writetolog method writes to eventlog
End Sub



Thanks

Niclas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top