private static string GetProcessPathUsingPsApi(int pid) {
var sw = Stopwatch.StartNew();
var processHandle = Kernel32.OpenProcess(Kernel32.ProcessAccessFlags.QueryInformation, false, pid);
if (processHandle == IntPtr.Zero) return null;
const int lengthSb = 4000;
try {
var sb = new StringBuilder(lengthSb);
return GetModuleFileNameEx(processHandle, IntPtr.Zero, sb, lengthSb) > 0 ? sb.ToString() : null;
} catch (Exception e) {
AcToolsLogging.Write(e);
return null;
} finally {
Kernel32.CloseHandle(processHandle);
AcToolsLogging.Write(sw.ElapsedMilliseconds + " ms");
}
}