473,385 Members | 1,326 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,385 software developers and data experts.

Is it possible to know if process started?

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?
Nov 16 '05 #1
3 5785
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" <DA***@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
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?


Nov 16 '05 #2

"DAMAR" <DA***@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
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.ProcStartEventArrive d);
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.
Nov 16 '05 #3
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" wrote:
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" <DA***@discussions.microsoft.com> wrote in message
news:3A**********************************@microsof t.com...
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?


Nov 16 '05 #4

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

Similar topics

12
by: serge calderara | last post by:
Dear all, I have an application which is suppose to start another executable process. As soon as that process is running, I need to retrive its handle. The problem of the particular process I am...
2
by: opt_inf_env | last post by:
Hello, Let us suppose that PHP file contains cycle which will never stop. For example: while ( 2==2 ) { some usage of database; } User which opens this PHP page runs time consuming execution...
2
by: Rick | last post by:
Hi, 1) HelloWorld.aspx?productID=abc123 2) HelloWorld.cs calls the database and gets a block of HTML code: string dbReturned = "<body>Hello World, <a href=http://localhost/?productID={NEED...
1
by: BenS | last post by:
Good Morning and Happy Wednesday! I've got a web service that exposes a method that takes an string input parameter that specifies an executable on the server that starts a process. These...
4
by: a | last post by:
Hi, The php script that processes user input from a form, starts a new process using exec. In my case, the process may contain arbitrary, user defined functionality. How do I ensure that that...
2
by: John Bradley | last post by:
I've looked high and low, but I can't seem to find an answer. When I open an application using the shell command, as seen below, how can I close the application? I am creating a menu system for...
2
by: Dax | last post by:
Does anyone know if there's a means by which I can invoke a Process.Start, then detach the process from the calling process. I suppose in a nutshell I'm asking if there's a way I can add the new...
6
by: mcse jung | last post by:
Here is asample program that writes a program and then executes it. Do you knowof a much simpler way of writing a program that writes a program? """...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.