为了账号安全,请及时绑定邮箱和手机立即绑定

获取Shell使用的文件图标

获取Shell使用的文件图标

FFIVE 2019-11-29 10:29:22
在.Net(C#或VB:无关)中,给定文件路径字符串,FileInfo结构或FileSystemInfo结构用于实际的现有文件,我如何确定外壳程序(浏览器)为此使用的图标文件?我目前不打算将其用于任何用途,但是当看到这个问题时,我对如何做到这一点感到好奇,并且我认为将其存档在SO上将很有用。
查看完整描述

3 回答

?
慕妹3146593

TA贡献1820条经验 获得超9个赞

Imports System.Drawing

Module 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 Function

End Module


查看完整回答
反对 回复 2019-11-29
  • 3 回答
  • 0 关注
  • 590 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信