public static string GetProcessPath(IntPtr hwnd)
{
try
{
uint pid = 0;
GetWindowThreadProcessId (hwnd, out pid);
Process proc = Process.GetProcessById ((int)pid); //Gets the process by ID.
return proc.MainModule.FileName.ToString (); //Returns the path.
}
catch (Exception ex)
{
return ex.Message.ToString ();
}
}