There's several things wrong with this. First, you should be iterating over the
pid2
variable not over
processlist
Second of all, you're trying to write
pid2
to the console, but this is an enumerable set. You need to print out information on the process itself (look at the
Process[
^] page in the documentation).
foreach (Process process in pid2)
{
Console.WriteLine("Process: {0} ID: {1}", process.ProcessName, process.Id);
Console.ReadLine();
}
Remember, you can rely on intellisense in Visual Studio to help you out. And remember, if you're getting results that you're not expecting, use the debugger to step through your code and work out what's wrong.