How can I control the process using C #?

I want my application to track and log a process that started and terminated on the winxp machine during the existence of my application. I do not want all process names to be started. How can I achieve this? Any ideas appreciated .. Thanks.

+3
source share
5 answers
public static void Monitor()
    { 
        ArrayList existingProcesses = GetExistingProcess();  

        while (true)
        {  
            ArrayList currentProcesses = new ArrayList();
            currentProcesses = GetCurrentProcess();

            ArrayList NewApps = new ArrayList(GetCurrentProcess());

            foreach (var p in ExistingProcess)
            {
                NewApps.Remove(p); 
            }
            string str = "";
            foreach (string NewApp in NewApps)
            {
                str = "Process Name : " + NewApp + "   Process ID : " + System.Diagnostics.Process.GetProcessesByName(NewApp)[0].Id.ToString() + " ";
            }
            MessageBox.Show(str);
        }
    }
0
source

, - Windows, - .

using System.Diagnostics;


// Poll every 5 seconds
while(true)
{
    // Get a list of running processes
    Process[] processlist = Process.GetProcesses();

    // Do logging
    // ...

    Thread.Sleep(5000);
}
+1

WMI... . this .

+1

, Process.GetProcesses.

You can then track each process in the returned array of processes.

+1
source

Source: https://habr.com/ru/post/1758347/


All Articles