Skip to content

Instantly share code, notes, and snippets.

@Criteo-dotnet-blog
Created November 13, 2018 10:19
Show Gist options
  • Save Criteo-dotnet-blog/e8541eb99372e92d747875a86d4baf0a to your computer and use it in GitHub Desktop.
Save Criteo-dotnet-blog/e8541eb99372e92d747875a86d4baf0a to your computer and use it in GitHub Desktop.
private static Type _processInfoType = null;
private static FieldInfo _processNameField = null;
public static string GetProcessNameByReflection(Process p)
{
var processInfoField = typeof(System.Diagnostics.Process)
.GetField("processInfo", BindingFlags.Instance | BindingFlags.NonPublic);
var processInfo = processInfoField.GetValue(p);
if (_processInfoType == null)
{
_processInfoType = processInfo.GetType();
_processNameField = _processInfoType.GetField("processName");
}
return _processNameField.GetValue(processInfo).ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment