Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Windows API win
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 19-Jul-13 4:36am
dur4N138
Comments
Richard MacCutchan at 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 at 19-Jul-13 11:31am
   
Are you running your application with administrator privileges?
dur4N at 19-Jul-13 11:34am
   
Good question Smile | :) To be honest, I don't want to get in trouble at my workplace.
dur4N at 19-Jul-13 11:35am
   
Yes I am running with administation privileges

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Comments
Espen Harlinn at 19-Jul-13 19:37pm
   
5'ed!
Sergey Alexandrovich Kryukov at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 718
1 OriginalGriff 420
2 CPallini 385
3 George Jonsson 231
4 Richard Deeming 145
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,272
3 George Jonsson 3,057
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 19 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100