Forum > Windows

[Solved]How to programmatically determine if an external .exe has embedded icons

(1/2) > >>

Ten_Mile_Hike:
Hi,
Simplest code to determine presence of embedded icon. NO NEED TO EXTRACT, just looking for presence

Thank You

Fibonacci:
You are in luck, I happen to have such code :)


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses Windows; function resenumtypes(hModule: HMODULE; lpType: LPSTR; lParam: LONG_PTR): BOOL; stdcall;begin  result := true;   if lpType = RT_ICON then begin    PBoolean32(lParam)^ := true;     result := false; //stop enumerating  end;end; var  h: hwnd;  has_icon: boolean = false; begin  h := LoadLibraryEx('C:\Windows\explorer.exe', 0, LOAD_LIBRARY_AS_IMAGE_RESOURCE+LOAD_LIBRARY_AS_DATAFILE);   if h > 0 then begin    EnumResourceTypes(h, @resenumtypes, LONG_PTR(@has_icon));     writeln('has icon? ', has_icon);  end else begin    writeln('cant open file');  end;   readln;end.

rvk:

--- Quote from: Fibonacci on August 29, 2023, 07:02:52 pm ---You are in luck, I happen to have such code :)

--- End quote ---
I'm not sure if ANY icon is what is asked for or the actual program icon.
Your code looks for ANY icon (of I'm not mistaken)?

You can use ExtractIconEx for the actual program icon.
https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-extracticonexa

You can probably use the ExtractIcon function for this.

Fibonacci:
He didn't specify it has to be MAINICON ;)

rvk:

--- Quote from: Fibonacci on August 29, 2023, 07:13:45 pm ---He didn't specify it has to be MAINICON ;)

--- End quote ---
No (s)he didn't but seeing that only the presence is requested it would make sense it would be the MAINICON.

Anyway, now both methods are documented in this topic  ;)

Navigation

[0] Message Index

[#] Next page

Go to full version