windows 使用 C# 检索完整的进程列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/599663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:05:02  来源:igfitidea点击:

Retrieve a complete processes list using C#

c#windowsprocess

提问by Richard

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.

我正在尝试编写一个 C# 程序来检索完整的进程列表。但是我发现一个应用程序打开了一个窗口,但我在 Windows 任务管理器的进程选项卡中没有看到它,我在任务选项卡中看到了它。此外,我也无法使用我的 C# 代码获取其信息。

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?

我浏览了很多论坛,但我只能找到隐藏进程的方法,我没有找到任何显示隐藏进程的方法。有谁知道如何检索隐藏的进程信息?

回答by Richard

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

Windows 上没有隐藏的进程。只有您没有(安全)权限查看的进程。

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

以管理员身份运行的进程(在 Vista/Win7/Win2k8 中需要提升)将始终能够看到所有进程。

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:

您需要保持您的进程,直到任务管理器更新其显示。最简单的方法是将以下语句添加到 Main 方法的末尾:

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

回答by Brian Rasmussen

I'm not sure what you mean. The code above lists the same number of processes as pslist. When you talk about methods to hide a process are you talking about root kits? If so they usually work by changing how the list commands work. I.e. the processes are in fact being enumerated, but the info is not displayed to the user.

我不确定你是什么意思。上面的代码列出了与pslist. 当您谈论隐藏进程的方法时,您是在谈论根工具包吗?如果是这样,它们通常通过更改 list 命令的工作方式来工作。即进程实际上正在被枚举,但信息不会显示给用户。

回答by Hannoun Yassir

it works just fine all you need is add :

它工作得很好,您只需要添加:

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

at the end or start project with ctrl + F5

最后或使用 ctrl + F5 启动项目