/// <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); }
/// <summary> /// 从进程获取Appx DisplayName /// </summary> /// <param name="process">PID</param> /// <returns>AppxPackage</returns> public static string GetAppDisplayNameFromProcess(Process process) { AppxPackage appxPackage = AppxPackage.FromProcess(process); string result = appxPackage.LoadResourceString(AppxPackage.FromProcess(process).Apps[0].DisplayName); if (string.IsNullOrEmpty(result)) { result = null; /*AppxPackage.FromProcess(process).Apps[0].DisplayName;*/ } return(result); }