问题描述
我尝试了两种方法来获取进程描述
I have tried in two ways to get the proocess description
解决方案 1:-
代码:-Process proc = Process.GetProcessById(pid);string process_description= proc.MainModule.FileVersionInfo.FileDescription
问题:-当我们尝试访问某些进程 0(空闲)、4(系统)或服务(具有管理员访问权限)的 MainModule 属性时(很可能是那些在 SYSTEM 凭据下运行的)用户没有权限导致 win32 ACCESS DENIED EXCEPTION.
Problem:-when we trying to access the MainModule property for some processes 0(idle), 4(system) or services(Having admin acces rights)(most likely those running under SYSTEM credentials) on which user don't have the permission leads to win32 ACCESS DENIED EXCEPTION.
解决方案 2:-
code :
string process_description=FileVersionInfo.GetVersionInfo(modulePath).FileDescription;
问题 :-如果在具有管理员权限的 exe 文件或进程的属性详细信息窗口中未提及文件描述,则无法获取进程描述.
Problem :-Unable to get process decription if file description is not mention in the properties details window of exe file or process which have admin rights .
例如:如果进程是谷歌浏览器.图片名称:-chrome.exe 描述:谷歌浏览器我想获得描述部分而不是图像名称.
For example:if process is google chrome.ImageName:-chrome.exe Description :Google chromeI want to get the description part not the Image Name.
任何人都可以分享您的想法如何在任务管理器中获取特定进程ID的进程描述.
Can any one share your ideas how to get process description in taskmanager for particular process id.
推荐答案
该信息包含在 VERSIONINFO
可执行文件的资源.您正在查找名为 FileDescription
的值.
The information is contained in the VERSIONINFO
resource for the executable file. You are looking for the value named FileDescription
.
使用 LoadLibraryEx
传递 LOAD_LIBRARY_AS_IMAGE_RESOURCE
.然后使用资源API,FindResource
、LoadResource
、LockResource
等获取版本信息资源.最后,解析出信息.
Use LoadLibraryEx
passing LOAD_LIBRARY_AS_IMAGE_RESOURCE
. And then use the resource API, FindResource
, LoadResource
, LockResource
etc. to obtain the version info resource. Finally, parse out the information.
或者,您可以直接解析 PE 文件,我怀疑任务管理器等程序出于性能原因会这样做.但这会复杂得多.
Alternatively you could parse the PE file directly which is what I suspect that programs like task manager do for performance reasons. But that would be much more complicated.
这篇关于如何根据进程ID获取进程描述?(c#.net)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!