How to get the .ico file of an arbitrary file?

Say I have a file and there is set an icon to it. How to get the icon which is figured on the file? File is an arbitrary - some extension about which I have no idea. Just how to get its icon.

EDIT: BTW the icon which is figured on the file is assigned when I told to SO open the file with an exe file I have created. And in that exe file there is no the icon that is on the file. Just, I guess, OS (Vista) have crated the icon of the file by takeing the icon of exe file and bu "putting" that on a white paper. SO I want to get this icon.


File association icons are assigned by Windows, most of which are found in %Windir%\system32\shell32.dll. You can find out which file provides a particular icon by going to Tools - Folder Options - File Types and then clicking the 'Advanced' button for your desired file type. Finally, click 'Change icon' in the window that appears and it will show you the path to the file's icon.

You can use Resource Hacker to export the icon from the file.


Batch Icon Extractor

Download BatchIconExtractor.exe and place it on your desktop. Drag and drop a file or a folder on the application icon. All icons from the file or from all files under the given folder are saved to a new folder called "icons". This folder is created in the same folder, where the application resides (Desktop by default).


The only way I know, apart from digging in the registry, is with .Net code. There's a function called ExtractAssociatedIcon() which gives you the associated icon with whichever file you pass it. Perhaps not the answer you're looking for, but there is no accessible interface built into Windows for this specific task ;)

Update: For making such an app, see http://pastie.org/1075055 (copy the code using the RAW button so avoid line numbers)