2

How can I get a Window's icon from its Pointer or Process/Process Name? The Icon shown in the corner of the Window or on the Task-bar or in the ALT-Tab menu.

Dor Cohen
  • 16,769
  • 23
  • 93
  • 161
Carsen Daniel Yates
  • 1,962
  • 1
  • 11
  • 16

2 Answers2

2

read about Icon.ExtractAssociatedIcon:

Returns an icon representation of an image that is contained in the specified file.

private void ExtractAssociatedIconEx()
{
    Icon ico =
        Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe");
    this.Icon = ico;

}

http://msdn.microsoft.com/en-us/library/system.drawing.icon.extractassociatedicon.aspx

This won't work on every process but it's a good start..

also take a look at those answers - How can I get the icon from the executable file only having an instance of it's Process in C#

Community
  • 1
  • 1
Dor Cohen
  • 16,769
  • 23
  • 93
  • 161
  • @CarsenDanielYates your welcome, if you liked the answer please check the green mark and +1 – Dor Cohen Apr 01 '12 at 22:00
  • 1
    This answer is wrong. The questions asks about the icon associated with a window rather than an executable. – David Heffernan Apr 01 '12 at 22:01
  • @DavidHeffernan Read the question again, How can I get a Window's icon from its Pointer or Process/Process Name?(PROCESS NAME) – Dor Cohen Apr 01 '12 at 22:02
  • Oh, Wait, sorry. This won't work, I need to be able to make a full shell alteration, I have to get the icon from running processes. – Carsen Daniel Yates Apr 01 '12 at 22:07
  • The next bit says "The Icon shown in the corner of the Window or on the Task-bar or in the ALT-Tab menu." and that's where WM_GETICON comes in. – David Heffernan Apr 01 '12 at 22:28
  • @DavidHeffernan Thanks for the comments, it seems like good answer. why won't you post it? or edit my answer if you wish – Dor Cohen Apr 01 '12 at 22:33
  • I don't want to answer because question is contradictory. Processes don't have icons. Exe files do. Windows do. But not processes. – David Heffernan Apr 01 '12 at 22:47
1

Would Icon.ExtractAssociatedIcon work for you?

jhenderson2099
  • 956
  • 8
  • 17