Is it possible to know if process started?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

Is it possible to know when a particular process started?
For example: I have such situation: I need to know when a notepad.exe is
started - i need to get an event of starting this process.
Can anyone help me?
 
Hi,

You can use the Process.GetProcesses method (in the System.Diagnostics
namespace) to get a list of processes currently running on the PC.

Process.GetProcessesByName() can also be used to just get a list of
instances of a particular program.

// Get all instances of Notepad running on the local computer.
Process [] localByName = Process.GetProcessesByName("notepad");
 
DAMAR said:
Hello

Is it possible to know when a particular process started?
For example: I have such situation: I need to know when a notepad.exe is
started - i need to get an event of starting this process.
Can anyone help me?

On XP and higher you can use the WMI kerneltrace provider through
System.Management.
Something like this will do....

using System.Management;
public class MyClass
{
// set-up asynch. event watcher
public void Run()
{
ManagementEventWatcher w = null;
ManagementOperationObserver observer = new ManagementOperationObserver();
WqlEventQuery q = new WqlEventQuery();
q.EventClassName = "Win32_ProcessStartTrace";
q.Condition = "ProcessName='Notepad.exe'"; // wait for notepad.exe
process start event
w = new ManagementEventWatcher( q);
w.EventArrived += new
EventArrivedEventHandler(this.ProcStartEventArrived);
w.Start();
}
private void ProcStartEventArrived(object sender, EventArrivedEventArgs e)
{
//Get the Event object and display all properties
foreach(PropertyData pd in e.NewEvent.Properties) {
Console.WriteLine("{0},{1}",pd.Name, pd.Value);
}
}
}

class WMIEvent {
[MTAThread]
public static void Main() {

MyClass evnt = new MyClass();
evnt.Run();
Console.ReadLine(); // block thread for demo purposes
....
}

Willy.
 
Hello

It is not what I expected
I'd like to know when a particullar process starts - it means, that the
process should pass me an event - "I just started". Process componen has only
"exit "event and it is not useful here.

Ross Donald said:
Hi,

You can use the Process.GetProcesses method (in the System.Diagnostics
namespace) to get a list of processes currently running on the PC.

Process.GetProcessesByName() can also be used to just get a list of
instances of a particular program.

// Get all instances of Notepad running on the local computer.
Process [] localByName = Process.GetProcessesByName("notepad");

--
Ross Donald
..NET Code Generation - http://www.radsoftware.com.au/codegenerator/


DAMAR said:
Hello

Is it possible to know when a particular process started?
For example: I have such situation: I need to know when a notepad.exe is
started - i need to get an event of starting this process.
Can anyone help me?
 
Back
Top