在c/c ++中获取进程名称 [英] getting processes names in c/c++
本文介绍了在c/c ++中获取进程名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
如何在c/c ++中按名称获取进程?我知道.net中的GetProcessesByName,但是c.
任何帮助都将受到欢迎.
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.
推荐答案
您将获得系统中所有进程的列表,然后过滤出您感兴趣的进程.
函数 EnumProcesses 将为您提供所有进程ID的列表.
Doc:http://msdn.microsoft.com/zh-CN/library/ms682629(v=VS.85).aspx
示例:http://msdn.microsoft.com/zh-cn/library/ms682623(v = VS.85).aspx
上面的示例调用函数 OpenProcess 来从进程ID中获取进程句柄,并且该句柄用于通过调用 EnumProcessModules 并从中获取模块句柄.可以调用 GetModuleBaseName 来获取要过滤的名称.
请注意,尽管这些是Windows系统提供的C函数,但它们不是C或C ++语言的一部分,而是特定于Windows的.
(作为一个附带说明,.NET框架比Win32 API更好用,在我看来并不那么谦虚,但在此问题上并非总是有选择的.)
无论如何,我希望这会有所帮助.
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.
您真的不会相信这个;)
http://msdn.microsoft.com/en-us/library/z3w4xdc9.aspx [ ^ ]
祝你好运!
You really will not believe this ;)
http://msdn.microsoft.com/en-us/library/z3w4xdc9.aspx[^]
Good luck!
这篇关于在c/c ++中获取进程名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文