|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Detecting process startI 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 Niclas,
In VB is to fire an event simple. The instruction is RaiseEvent, http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vastmraiseevent.asp However I think that you needs probably the waitforexit of process http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdiagnosticsprocessclasswaitforexittopic2.asp I hope this helps, Cor Show quoteHide quote "Niclas" <lindblom_nic***@hotmail.com> schreef in bericht news:urM2jWDRGHA.4344@TK2MSFTNGP12.phx.gbl... > 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 > >
Collections challenge (MRU)
Retrieve data from xml document Determining the Browser and event.keyCode vs. event.which difference between ME and MYCLASS Createing the Domain searce dialog Inheritance doubt. hair cross cursor advice needed for a good book to make good database applications VB.Net & SQL2005 Stored Procedures How select from 2 ADO.NET DataTables? |
|||||||||||||||||||||||