Thursday, November 25, 2010

How to get Parent Process Path

using System.Management;

private String GetParentProcessPath(int CurrentProcessId)
{
int iParentPid = 0;
using (ManagementObject objMgmt= new ManagementObject("win32_process.handle='"+ Id.ToString() + "'"))
{
objMgmt.Get();
iParentPid = Convert.ToInt32(mo["ParentProcessId"]);
}

Process objPrc = Process.GetProcessById(iParentPid);

String sParentDirPath = Path.GetDirectoryName(objPrc.Modules[0].FileName);
return sParentDirPath;
}

No comments:

Followers

Link