Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
571 views
in Technique[技术] by (71.8m points)

windows - Retrieve a complete processes list using C#

I am trying to write a C# program to retrieve a complete process list. However I find that an application open a window but I don't see it in the process tab of Windows task manager, I see it in task tab. In addition, I also cannot get its information using my C# code.

static void showProcesses()
{
    Process[] procs = Process.GetProcesses();

    foreach (Process proc in procs)
    {
        Console.WriteLine(proc.ProcessName);
    }
}

I browsed many forums but I can only find the methods to hide a process, and I don't find any method for showing hidden processes. Do anyone have idea how to retrieve hidden process information?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There are no hidden processes on Windows. Only processes you do not have (security) rights to see.

A process running as an administrator (in Vista/Win7/Win2k8 would need to be elevated) will always be able to see all processes.

However, a console application that lists the processes may well exit before Task Manager's display refreshes, and thus won't be seen. This is likely with a simple program even with update speed set to "high".

You need to keep your process around until Task manager has updated its display. The simplest way would be do add the following statements to the end of your Main method:

Console.Write("Press ENTER to exit");
Console.ReadLine();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...