Example #1
0
        /// <summary>
        /// 获取进程路径
        /// </summary>
        /// <param name="process">进程</param>
        /// <returns>进程路径</returns>
        public static string GetProcessPath(Process process)
        {
            bool isUWP = MyProcessHelper.IsProcessUWP(process);

            string applicationPath = "";

            if (isUWP)
            {
                try
                {
                    List <IntPtr> allChildWindows = MyWindowHelper.GetAllChildHandles(process.MainWindowHandle);
                    foreach (IntPtr ptr in allChildWindows)
                    {
                        Process uwpProcess = MyProcessHelper.GetWindowPID(ptr);
                        if (uwpProcess.MainModule.ModuleName != "ApplicationFrameHost.exe")
                        {
                            applicationPath = uwpProcess.MainModule.FileName;
                        }
                    }
                }
                catch { applicationPath = null; }
            }
            else
            {
                applicationPath = process.MainModule.FileName;
            }

            return(applicationPath);
        }
Example #2
0
        /// <summary>
        /// 获取进程图标
        /// </summary>
        /// <param name="process">进程</param>
        /// <returns>图标</returns>
        public static Bitmap GetProcessIcon(Process process)
        {
            bool isUWP = MyProcessHelper.IsProcessUWP(process);

            Bitmap result = new Bitmap(Properties.Resources.Default.ToBitmap());

            if (isUWP)
            {
                try
                {
                    List <IntPtr> allChildWindows = MyWindowHelper.GetAllChildHandles(process.MainWindowHandle);
                    foreach (IntPtr ptr in allChildWindows)
                    {
                        Process uwpProcess = MyProcessHelper.GetWindowPID(ptr);
                        if (uwpProcess.MainModule.ModuleName != "ApplicationFrameHost.exe")
                        {
                            AppxPackage package = AppxPackage.FromProcess(uwpProcess);
                            result = new Bitmap(package.FindHighestScaleQualifiedImagePath(package.Logo));
                        }
                    }
                }
                catch { result = new Bitmap(Properties.Resources.Default.ToBitmap()); }
            }
            else
            {
                result = Icon.ExtractAssociatedIcon(GetProcessPath(process)).ToBitmap();
            }

            return(result);
        }
Example #3
0
        /// <summary>
        /// 获取进程名称
        /// </summary>
        /// <param name="process">进程</param>
        /// <returns>进程名称</returns>
        public static string GetProcessName(Process process)
        {
            bool isUWP = MyProcessHelper.IsProcessUWP(process);

            string applicationName = "";

            if (isUWP)
            {
                try
                {
                    List <IntPtr> allChildWindows = MyWindowHelper.GetAllChildHandles(process.MainWindowHandle);
                    foreach (IntPtr ptr in allChildWindows)
                    {
                        Process uwpProcess = MyProcessHelper.GetWindowPID(ptr);
                        if (uwpProcess.MainModule.ModuleName != "ApplicationFrameHost.exe")
                        {
                            applicationName = MyAppxPackageHelper.GetAppDisplayNameFromProcess(uwpProcess);
                            if (string.IsNullOrEmpty(applicationName))
                            {
                                applicationName = MyWindowHelper.GetWindowTitle(ptr);
                            }
                            break;
                        }
                    }
                }
                catch { applicationName = null; }
            }
            else
            {
                applicationName = process.MainModule.FileVersionInfo.FileDescription;

                if (string.IsNullOrEmpty(applicationName))
                {
                    applicationName = process.ProcessName;
                }
            }

            return(applicationName);
        }