Click here to Skip to main content
15,904,024 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,

How can I get processes by name in c/c++? I know GetProcessesByName in .net but how about c.

Any help would be welcome.
Posted

You get a list of all processes in the system, and filter out the ones you are interested in afterwards.

The function EnumProcesses will get you a list of all process ids.
Doc: http://msdn.microsoft.com/en-us/library/ms682629(v=VS.85).aspx
Example: http://msdn.microsoft.com/en-us/library/ms682623(v=VS.85).aspx

The example above calls the function OpenProcess to get a process handle from a process id, and this handle is used to get a module handle via a call to EnumProcessModules, and from this GetModuleBaseName can be called to get a name for you to filter on.

Note that while these are C functions offered by the Windows system, they aren't part of the C or C++ languages, and are specific to Windows.

(As a side note, the .NET framework is much nicer to work with than the Win32 API, in my not so humble opinion, but one doesn't always have a choice in the matter.)

Anyway, I hope this helps.
 
Share this answer
 
Comments
ali_azin 7-Aug-10 0:18am    
Reason for my vote of 4
Complete docs, example
ali_azin 7-Aug-10 0:19am    
thanks for reply.
I should do this in C because I'm writing a plugin for an application that only support C/C++.
You really will not believe this ;)

http://msdn.microsoft.com/en-us/library/z3w4xdc9.aspx[^]

Good luck!
 
Share this answer
 
Comments
Niklas L 6-Aug-10 16:47pm    
Oh! :)
Yusuf 6-Aug-10 21:21pm    
I thought the OP asked for C not C#
Sauro Viti 9-Aug-10 2:36am    
Yusuf, I think that E.F. Nijboer was talking about C++/CLI: the same API is available to all the languages that support the .NET Framework
E.F. Nijboer 9-Aug-10 3:30am    
That is correct. When you follow the link the example shown is VB and have to choose the language preferred.

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