用 C 检索 Windows 进程的完整列表 [英] Retrieving a complete list of Windows processes in C

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

问题描述

我正在为 Windows 开发一个简单的进程统计信息收集库.我正在使用 EnumProcesses() 函数枚举进程,并尝试使用带有 PROCESS_QUERY_INFORMATION 标志的 OpenProcess() 调用打开它们.不过,后者在一堆系统进程中失败了.同时,我看到类似的应用程序(系统内部工具、任务管理器等)似乎能够检索有关这些进程的信息,即使不需要管理员权限.我尝试启用 SeDebugPrivilege 权限,但只有当我以管理员身份运行我的程序时它才有所帮助——而且,我仍然无法打开空闲进程、系统进程和 audiodg 进程(我希望能够检索他们的信息的一致性).

I am developing a simple process statistics collection library for Windows. I'm enumerating the processes with EnumProcesses() function, and I try to open them with OpenProcess() call with PROCESS_QUERY_INFORMATION flag. The latter one fails for a bunch of system processes, though. At the same time, I see that similar applications (sysinternals tools, task manager, etc) seem to be able to retrieve information about these processes even without requiring Administrator privileges. I tried enabling the SeDebugPrivilege privilege, but it did help only when I ran my program as an Administrator -- and still, I could not open the Idle process, the System process and the audiodg process (I would like to be able to retrieve their information for consistency as well).

所以问题是:我怎样才能获得有关所有进程的信息(我看到它是由 3rd 方应用程序完成的,但我不知道是如何完成的)?没有管理员权限是否可以执行此操作?

So the question is: how can I get information about all the processes (I see it done by 3rd-party applications, but I don't see how)? Is it possible to do it without Administrator privileges?

推荐答案

您是否熟悉 CreateToolhelp32Snapshot 和这个功能以及Process32First.

Are you familiar with CreateToolhelp32Snapshot and this function as well Process32First.

我发现这个 code-project 当我前段时间用过它对我帮助很大......

I have found this code-project When I used it a while ago it helped me a lot ...

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

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