如何获取基于流程ID的流程说明?(c#.net)

问题描述:

我已经尝试了两种方法来获取过程描述

I have tried in two ways to get the proocess description

解决方案1:-

代码:-
Process proc = Process.GetProcessById(pid);
字符串process_description = proc.MainModule.FileVersionInfo.FileDescription

问题:-当我们尝试访问某些用户没有权限的进程0(空闲),4(系统)或服务(具有管理员访问权限)
(最有可能在SYSTEM凭据下运行的那些进程)的MainModule属性会导致win32 ACCESS拒绝例外。

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 .

例如:如果进程是google chrome。
ImageName:-chrome.exe说明:Google chrome
我想获取描述部分而不是图像名称。

For example:if process is google chrome. ImageName:-chrome.exe Description :Google chrome I want to get the description part not the Image Name.

任何人都可以分享您的想法,如何在taskmanager中获取特定过程ID的过程描述。

Can any one share your ideas how to get process description in taskmanager for particular process id.

该信息包含在 VERSIONINFO 资源。您正在寻找名为 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.