获取Shell使用的文件图标

在.Net(C#或VB:无关)中,给定文件路径字符串,FileInfo结构或FileSystemInfo结构用于实际的现有文件,我如何确定外壳程序(浏览器)为此使用的图标文件?


我目前不打算将其用于任何用途,但是当看到这个问题时,我对如何做到这一点感到好奇,并且我认为将其存档在SO上将很有用。


FFIVE
浏览 596回答 3
3回答

慕妹3146593

Imports System.DrawingModule Module1    Sub Main()            Dim filePath As String =  "C:\myfile.exe"          Dim TheIcon As Icon = IconFromFilePath(filePath)          If TheIcon IsNot Nothing Then                ''#Save it to disk, or do whatever you want with it.            Using stream As New System.IO.FileStream("c:\myfile.ico", IO.FileMode.CreateNew)                TheIcon.Save(stream)                      End Using        End If    End Sub    Public Function IconFromFilePath(filePath As String) As Icon        Dim result As Icon = Nothing        Try            result = Icon.ExtractAssociatedIcon(filePath)        Catch ''# swallow and return nothing. You could supply a default Icon here as well        End Try        Return result    End FunctionEnd Module
打开App,查看更多内容
随时随地看视频慕课网APP