コード例 #1
0
 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);
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }