问题
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