0

I want to get the list of applications(preferably Metro or UWP) apps that are currently running in the system and consuming CPU&Memory. I need the application name as well as the image associated with the application as shown in the image below. enter image description here As we can see in the image that Microsoft Edge is being displayed with its icon.

I have a piece of code that helps me in getting the CPU consumption details.

Process[] processlist = Process.GetProcesses();

foreach(Process theprocess in processlist){
Console.WriteLine(“Process: {0} ID: {1}”, theprocess.ProcessName, theprocess.Id);
}

I want to have image icon as well as the name of preferably UWP /Store apps.

Apoorv
  • 2,023
  • 1
  • 19
  • 42
  • why did you vote it to be closed? I need help ! – Apoorv Feb 24 '16 at 06:17
  • 1
    This is essentially the same [as your prior closed question](http://stackoverflow.com/questions/35474697/getting-the-cpu-memory-storage-usage-for-modern-apps-using-wpf-app). Your code snippet doesn't address _"getting the CPU consumption details"_ anyway. Not to mention **there is no question actually being asked** –  Feb 24 '16 at 06:19
  • apart from closing this , you can help or guide me ? atleast i am trying to do anything? any clues or anything shall be helpful. – Apoorv Feb 24 '16 at 06:19

1 Answers1

1

If you're looking for the icon of the running process, then you can get it like this

Icon icon = Icon.ExtractAssociatedIcon(theprocess.MainModule.FileName);

Then you can convert it to Bitmap like this,

var iconImage = icon.ToBitmap();

Namespace : System.Drawing;

Hope this helps.

Vishnu Prasad V
  • 1,228
  • 1
  • 8
  • 18
  • any namespace to include for this ? what i want to do is to extract a list of runing process with their names and the app icon associated with that – Apoorv Feb 24 '16 at 06:25
  • Add this code inside your foreach loop. `theprocess` is your foreach iteration variable. – Vishnu Prasad V Feb 24 '16 at 06:27
  • i made a console application and run VS as Admin. I am getting Win32Exception - An unhandled exception of type System.ComponentModel.Win32Exception occured in System.Dll .. Access is denied – Apoorv Feb 24 '16 at 08:46
  • @Apoorv There are plenty of reasons why you get an `Acess is denied` exception. accessing a x64 process from a 32bit process, trying to access a `System` process etc. Please see this link for more details http://stackoverflow.com/q/3399819/5077042 – Vishnu Prasad V Feb 24 '16 at 09:37
  • I was going through many. some say the compilation should be AnyCPU ..and its the same for me ! let me check and get back to you – Apoorv Feb 24 '16 at 09:39
  • something or the other is missing..this time its unable to resolve ProcessAccessFlags – Apoorv Feb 24 '16 at 09:43
  • Is basically this: http://stackoverflow.com/questions/462270/get-file-icon-used-by-shell – Kelly Feb 25 '16 at 06:10