public static string GetApplicationPathFromProcess(Process proc) { try { if (!SystemUtils.IsOSWinXP()) { return(GetProcessExecutionPath.GetExecutablePathAboveVista(new UIntPtr((uint)proc?.Id.Value))); } if (SystemUtils.IsAdministrator()) { return(proc?.MainModule.FileName.ToString((IFormatProvider)CultureInfo.InvariantCulture)); } } catch { } return(string.Empty); }
public static string GetExecutablePathAboveVista(UIntPtr dwProcessId) { StringBuilder buffer = new StringBuilder(1024); IntPtr num = GetProcessExecutionPath.OpenProcess(4096, false, dwProcessId); if (num != IntPtr.Zero) { try { int size = buffer.Capacity; if (GetProcessExecutionPath.QueryFullProcessImageName(num, 0, buffer, out size)) { return(buffer.ToString()); } } finally { GetProcessExecutionPath.CloseHandle(num); } } return(string.Empty); }
public static List <string> GetApplicationPath(Process[] procList) { List <string> stringList = new List <string>(); if (procList != null) { foreach (Process proc in procList) { try { string applicationPathFromProcess = GetProcessExecutionPath.GetApplicationPathFromProcess(proc); if (!string.IsNullOrEmpty(applicationPathFromProcess)) { stringList.Add(applicationPathFromProcess); } } catch (Exception ex) { } } } return(stringList); }