473,406 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Detecting process start

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").Va lue.ToString,
EventLogEntryType.Error)
'Writetolog method writes to eventlog
End Sub

Thanks

Niclas
Mar 10 '06 #1
1 3088
Niclas,

In VB is to fire an event simple. The instruction is RaiseEvent,

http://msdn.microsoft.com/library/de...raiseevent.asp

However I think that you needs probably the waitforexit of process

http://msdn.microsoft.com/library/de...exittopic2.asp
I hope this helps,

Cor

"Niclas" <li*************@hotmail.com> schreef in bericht
news:ur**************@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").Va lue.ToString,
EventLogEntryType.Error)
'Writetolog method writes to eventlog
End Sub

Thanks

Niclas

Mar 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Joecx | last post by:
Hi Does anyone have the code or maybe give me a start on how to detect if my program is already running if someone tries to run it again while it's already running? I know I could do this with a...
6
by: Andrea | last post by:
I need to detect when another application is launched. I'd need to know also when a new folder is opened in explorer. I'm developing an application to speed up access to frequently used...
0
by: bamapookie | last post by:
I've written an app that starts and monitors a number of processes. If one of those processes dies, the app restarts it. One of the options I've written hides the main window of the monitored...
0
by: bamapookie | last post by:
I'm sorry if this was posted several times. I did not see my previous post appear after I posted it. I've written an app that starts and monitors a number of processes. If one of those...
2
by: pmclinn | last post by:
I have a couple spyware bots I loaded on a test machine. While I was watching the spyware infect the system I noticed that it was launching a process but it was not listed in my task Managaer...
3
by: Graeme Hinchliffe | last post by:
Hiya I have now managed to get my code to function correctly for a none present db, and one that is shutdown whilst it is being used. In both cases my code functions and happily recovers on the...
2
by: James Colannino | last post by:
Hey everyone. I'm writing a small application in Python that uses os.fork() to create a separate process in which another application is run in the background. The problem is that I need to know...
3
by: Simon | last post by:
Hi everyone, Can anyone tell me if there is a standard way of detecting an error in a process that I've started using the .net framework's System.Diagnostics.Process class? I need to...
13
by: Ilias Lazaridis | last post by:
How to detect memory leaks of python programms, which run in an environment like this: * Suse Linux 9.3 * Apache * mod_python The problem occoured after some updates on the infrastructure....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.