使用 C# 检索完整的进程列表 [英] Retrieve a complete processes list using C#

查看:10
本文介绍了使用 C# 检索完整的进程列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个 C# 程序来检索完整的进程列表.但是我发现一个应用程序打开了一个窗口,但我在 Windows 任务管理器的进程选项卡中没有看到它,我在任务选项卡中看到了它.此外,我也无法使用我的 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?

推荐答案

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

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

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

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".

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

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();

这篇关于使用 C# 检索完整的进程列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆