Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing external exe icon at runtime

Tags:

c#

.net

I'm developing a simple application which is supposed to simply copy another existing executable file and change it's icon. Is this possible to achieve with .NET? I'm asking about icon changing, copying is not a problem.

I have no clues on how and where to start. I've searched on Google, but found only unmanaged C++ code which I'm not very much familiar with.

This post has nothing with changing current application's icon at runtime, rather it's about changing the icon of an external application (that's visible in Windows Explorer).

Any help would be appreciated.

Thanks.

like image 330
Nikola Malešević Avatar asked Aug 20 '26 05:08

Nikola Malešević


1 Answers

.NET has no support for this whatsoever. The icon is stored in the unmanaged resources embedded in a .exe. You can see them with File + Open + File, select the .exe and open the Icons node. The lowest numbered icon is the one Windows uses.

Updating those resources normally requires rebuilding the .exe. Luckily the Windows API has support for updating resources on-the-fly. It has restrictions but that shouldn't affect you for icons. You'll need BeginUpdateResource, UpdateResource and EndUpdateResource. Beware that they are not easy to use, you need to know the icon resource number. Visit pinvoke.net for the declarations you will need.

like image 73
Hans Passant Avatar answered Aug 22 '26 18:08

Hans Passant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!