Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving an exe file's icon. 1

Status
Not open for further replies.

aliinal

Technical User
Jun 26, 2001
104
TR
Hi everyone,

is it possible to get an exe file's icon programmatically?

hope anyone knows this

bye
 
I found a class at the folliwng URL ( that should solve your problem. I have reposted it here for convenience sake.
Code:
'NOTE Icon Extractor 
'This Class enables to extract icon from dll or exe 

Imports System 
Imports System.Drawing 
Imports System.Runtime.InteropServices 

Public Class ExtractIcon 

    <Flags()> Private Enum SHGFI 
        SmallIcon = &H1 
        LargeIcon = &H0 
        Icon = &H100 
        DisplayName = &H200 
        Typename = &H400 
        SysIconIndex = &H4000 
        UseFileAttributes = &H10 
    End Enum 

    Public Enum IconType 
        SmallIcon = True 
        LargeIcon = False 
    End Enum 

    <StructLayout(LayoutKind.Sequential)> _ 
    Private Structure SHFILEINFO 
        Public hIcon As IntPtr 
        Public iIcon As Integer 
        Public dwAttributes As Integer 
        <MarshalAs(UnmanagedType.LPStr, SizeConst:=260)> _ 
        Public szDisplayName As String 
        <MarshalAs(UnmanagedType.LPStr, SizeConst:=80)> _ 
        Public szTypeName As String 

        Public Sub New(ByVal B As Boolean) 
            hIcon = IntPtr.Zero 
            iIcon = 0 
            dwAttributes = 0 
            szDisplayName = vbNullString 
            szTypeName = vbNullString 
        End Sub 
    End Structure 

    Private Declare Auto Function SHGetFileInfo Lib &quot;shell32&quot; ( _ 
    ByVal pszPath As String, ByVal dwFileAttributes As Integer, _ 
    ByRef psfi As SHFILEINFO, ByVal cbFileInfo As Integer, ByVal uFlagsn As SHGFI) As Integer 

    Public Shared Function GetIcon(ByVal Path As String, Optional ByVal Ico As IconType = True) As Icon 
        Dim info As New SHFILEINFO(True) 
        Dim cbSizeInfo As Integer = Marshal.SizeOf(info) 
        Dim flags As SHGFI = SHGFI.Icon Or SHGFI.UseFileAttributes 
        If Ico = True Then 
            flags += SHGFI.SmallIcon 
        Else 
            flags += SHGFI.LargeIcon 
        End If 
        SHGetFileInfo(Path, 256, info, cbSizeInfo, flags) 
        Return Icon.FromHandle(info.hIcon) 
    End Function 

End Class
 
that's incredible!

thank you...
@li
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top