On May 14, 2:34 pm, Jeff Williams
<jeff.williams_NO_S...@hardsoft.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.Managment namespace, .NET 2.0)
// Create event query to be notified within 1 second of
// a change in a process
string query =
"SELECT * FROM __InstanceCreationEvent "
+ "WITHIN 1 WHERE " +
"TargetInstance isa \"Win32_Process\"";
// Initialize an event watcher and subscribe to events
// that match this query
ManagementEventWatcher watcher =
new ManagementEventWatcher(new EventQuery(query));
// times out watcher.WaitForNextEvent 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.WriteLine(
"Open an application (notepad.exe) to trigger an
event.");
ManagementBaseObject e = watcher.WaitForNextEvent();
//Display information from the event
Console.WriteLine(
"Process {0} has been created, path is: {1}",
((ManagementBaseObject)e
["TargetInstance"])["Name"],
((ManagementBaseObject)e
["TargetInstance"])["ExecutablePath"]);
Console.ReadLine();
//Cancel the subscription
watcher.Stop();
return 0;
This sample is from MSDN.
That's an off-handed idea, there might be better solutions.
Moty