I have a small problem while developing an application. I want to access all process of the current session only. Currently I am using Process
class but it will return all process of all session.
Please help me to get process of the current active session only not all.
Help needed to solve the problem.
This will give you a list of the process running that are running with the same SessionId
as
the current process. I think that is what you want.
Process[] runningProcesses = Process.GetProcesses();
var currentSessionID = Process.GetCurrentProcess().SessionId;
Process[] sameAsThisSession =
runningProcesses.Where(p => p.SessionId == currentSessionID).ToArray();
foreach (var p in sameAsThisSession)
{
Trace.WriteLine(p.ProcessName);
}