C ++ Windows OpenProcess问题 [英] C++ Windows OpenProcess problem

查看:150
本文介绍了C ++ Windows OpenProcess问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个关于OpenProcess功能的严重问题(链接到msdna )。



我需要该功能来获取所有进程处理,收集有关当前正在运行的进程的基本信息(进程名称,CPU使用情况,内存使用情况)。问题是当我构建我的应用程序的发布版本时,某些进程句柄无法使用此函数打开(调试版本成功打开这些句柄)。我尝试了几种解决方案,但其中一些有瓶颈。这个解决方案是:

- 初始化权限,还需要Open Process功能,失败的是我的应用程序无法打开自己的句柄。

- 尝试其他功能来获取进程名称和CPU使用率(这些都没问题)



不幸的是,我找不到另一种获取进程内存使用的方法,这就是OpenProcess需要解决的原因,但是如果你有一个想法,没有OpenProcess收集内存使用信息,请让我知道或解决OpenProcess失败。



很抱歉不共享程序代码,但其商业秘密目前。

Hi,

I have a serious problem about OpenProcess function (link to msdna).

I need that function to get all process handles, to collect basic information (process name, cpu usage, memory usage) about the currently running processes. The problem is when I build a release version of my application some process handle cannot be opened with this function (debug version open these handles succesfully). I've tried several solution, but some of them have a bottleneck. This "solutions" was:
- Initialize privileges, also need Open Process function, the failure was my application cannot open its own handle.
- Tried other function to get process name and cpu usage (these are ok)

Unfortunately, I cannot found another way to get memory usage of processes, thats is why OpenProcess needs to be solved, but if you have an idea to collect memory usage info without OpenProcess please let me know that or solve the OpenProcess failure.

Sorry about not sharing the program code, but its trade secret currently.

推荐答案

根据您的描述,目前尚不清楚正在发生的事情以及您正在努力实现的目标。可能你需要枚举进程:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682629%28v=vs.85%29.aspx [ ^ ],

http://msdn.microsoft.com /en-us/library/windows/desktop/ms682623%28v=vs.85%29.aspx [ ^ ]。



或者,如果您对一个流程的信息感兴趣,您可以在流程本身之外的流程之外获取此流程的句柄。对于外部方法,您必须在其他进程中创建进程并获取父进程中的进程句柄: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx [<一个href =http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspxtarget =_ blanktitle =New Window> ^ ]。



如果您想在当前流程中执行此操作,则需要获取当前流程句柄并执行相同操作: http://msdn.microsoft.com/en-us/library/ms683179%28v=vs。 85%29.aspx [ ^ ]。



-SA
It's not quite clear, according to your description, what's going on and what you are trying to achieve, exactly; probably you need to enumerate processes:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682629%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682623%28v=vs.85%29.aspx[^].

Alternatively, if you are interested in the information on just one process, you can get the handle of this process outside of this process, on in the process itself. For outside approach, you have to create the process in some other process and obtain the process handle in the parent process: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425%28v=vs.85%29.aspx[^].

If you want to do it in your current process, you need to obtain your current process handle and do the same: http://msdn.microsoft.com/en-us/library/ms683179%28v=vs.85%29.aspx[^].

—SA


这篇关于C ++ Windows OpenProcess问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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