I'm trying to monitor every process when it starts on my machine.
Monitoring processes after they started is no problem with this class:
class ProcessHelper
{
ManagementEventWatcher processListener;
public ProcessHelper()
{
processListener = new ManagementEventWatcher(new WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace"));
processListener.EventArrived += new EventArrivedEventHandler(ProcessListener_ProcessStarted);
processListener.Start();
}
PropertyDataCollection.PropertyDataEnumerator propEnum;
private void ProcessListener_ProcessStarted(object sender, EventArrivedEventArgs e)
{
propEnum = e.NewEvent.Properties.GetEnumerator();
while(propEnum.MoveNext())
{
//DoMyStuff
}
}
public void stopListener()
{
processListener.Stop();
}
}
But I want to do this before the process starts, and interrupt its start.
What my goal is: I want to get notified when a process starts. I will also need its full filepath. Then i want to interrupt the start. (Lets call it "freeze" the process)
When the process is frozen, i want to do some checks, and after these kill it or let it start.
//EDIT
I think i found out how to freeze processes, in this thread.
So i "just" need to know how i can get notified when a process starts, to instant freeze it.
Its no problem to use C/C++ librarys.
I want to develop the application with .NET Framewok 2.0 - 4.0
Does anyone know if (and how) this is possible in C#?