On May 14, 2:34 pm, Jeff Williams
<jeff.williams_ NO_S...@hardsof t.com.auwrote:
I need to monitor for when an exe (application) starts. This will
trigger an alert. The application will be one the user starts and
monitoring will be only required on the pc they are logged in on.
Could someone direct me to what the best way to do this is.
Regards
Jeff
Dear Jeff,
you can watch for WMI events (System.Managme nt namespace, .NET 2.0)
// Create event query to be notified within 1 second of
// a change in a process
string query =
"SELECT * FROM __InstanceCreat ionEvent "
+ "WITHIN 1 WHERE " +
"TargetInst ance isa \"Win32_Process \"";
// Initialize an event watcher and subscribe to events
// that match this query
ManagementEvent Watcher watcher =
new ManagementEvent Watcher(new EventQuery(quer y));
// times out watcher.WaitFor NextEvent in 20 seconds
watcher.Options .Timeout = new TimeSpan(0, 0, 20);
// Block until the next event occurs
// Note: this can be done in a loop if waiting for
// more than one occurrence
Console.WriteLi ne(
"Open an application (notepad.exe) to trigger an
event.");
ManagementBaseO bject e = watcher.WaitFor NextEvent();
//Display information from the event
Console.WriteLi ne(
"Process {0} has been created, path is: {1}",
((ManagementBas eObject)e
["TargetInstance "])["Name"],
((ManagementBas eObject)e
["TargetInstance "])["ExecutablePath "]);
Console.ReadLin e();
//Cancel the subscription
watcher.Stop();
return 0;
This sample is from MSDN.
That's an off-handed idea, there might be better solutions.
Moty