Monday, December 3, 2012

Extract icon from file

Extract icons from any exe and dll files. There is 2 way to extract an icon from a file in Windows : the easy way and the hard way.
Today, I’ll show you the easy way using the ExtractAssociatedIcon from the System.Drawing.Icon Namspace.

Let’s say you have a form in Visual Basic Express 2010 or Visual Studio 2010 and you would like to change the default icon for another one.

[Default icon]

You have to choose the icon from the file. Identify the path and the full file name. In my example, I choose the logo from Windows about :


Here is what your code would look like:

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        If System.IO.File.Exists("C:\Windows\System32\winver.exe") Then
            Me.Icon = System.Drawing.Icon.ExtractAssociatedIcon("C:\Windows\System32\winver.exe")
        End If

    End Sub

The final result if you run your code, the logo from your file is reused in your project or your form.


I invite you to visit my blog for more articles and leave a comment. Check Technologies represents more than 10 years .... Computer and computer aided design.

235 Adrien-Provencher
Beloeil, (Québec), J3G 0C8, Canada
Tel : 514-705-7690


  1. How to extract icon providing a extension. Lets say I need a pdf icon from windows or doc icon.

    Best Regards,


  2. How do we extract a icon with the extension of a file from windows. lets say i need a pdf icon or a doc icon by passing extension.

    Best Regards,


    1. Hi Sam,
      Here is the general idea:

      #1 : Find the default application from your extension in the registry (exemple : HKEY_CLASSES_ROOT\Applications\iTunes.exe\DefaultIcon or HKEY_CLASSES_ROOT\Applications\wmplayer.exe\DefaultIcon)
      #2 : you should have a path that leads you to a file. Extract the image or icon (Exemple : %SystemRoot%\system32\wmploc.dll,-730)

      You need the default application because the icon looks different if is oppenned from one program or an other.