Getting process information in .NET

泪湿孤枕 提交于 2019-12-11 16:42:11

问题


Duplicate of this question.

update - This is not an exact duplicate. See my solution.

I see a java.exe process in process explorer, and double clicking it gives me its working directory & starting command line arguments.

From .NET, I run the following code and get a process with the same PID but the above fields are empty. Apparently, this is documented.

foreach (Process process in Process.GetProcessesByName("java"))
{ 
  ...
}

So how do I get the correct startinfo field values, without peeking into process memory by hand (in other words - I'd like to steal this code from somewhere instead of hack the process memory myself).


回答1:


Per the post that you listed in your question the way to do it is to peek into the process memory. The .NET classes will NOT load the data since you didn't start the process from .NET.




回答2:


I wrote some code the accomplish this (blog post and direct link to zip).

In short: this question helped a lot. I took the CodeProject code and wrapped it in a command line utility and then a C# wrapper.



来源:https://stackoverflow.com/questions/439653/getting-process-information-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!