Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
Richard MacCutchan 19-Jul-13 11:30am    
How can your code be a trade secret when it is merely using the Windows API to get process handles?
Richard MacCutchan 19-Jul-13 11:31am    
Are you running your application with administrator privileges?
dur4N 19-Jul-13 11:34am    
Good question Smile | :) To be honest, I don't want to get in trouble at my workplace.
dur4N 19-Jul-13 11:35am    
Yes I am running with administation privileges

1 solution

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
 
Share this answer
 
Comments
Espen Harlinn 19-Jul-13 19:37pm    
5'ed!
Sergey Alexandrovich Kryukov 19-Jul-13 20:26pm    
Thank you, Espen.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900