你如何从shell32.dll中获取图标?

我想要树图标用于本地应用程序。 有谁知道如何提取图像作为.icon文件? 我喜欢16×16和32×32,或者我只是做一个屏幕截图。

在Visual Studio中,select“文件打开…”,然后select“文件…”。 然后selectShell32.dll。 文件夹树应该被打开,你会在“图标”文件夹中find图标。

要保存图标,可以右键单击文件夹树中的图标,然后select“导出”。

另一种select是使用ResourceHacker等工具。 它处理的方式不仅仅是图标。 干杯!

如果有人正在寻找一个简单的方法,只需使用7zip解压缩shell32.dll,并寻找文件夹.src / ICON /

我需要从shell32.dll中提取图标#238,并且不想下载Visual Studio或Resourcehacker,所以我从Technet发现了几个PowerShell脚本(感谢John Grenfell和#https://social.technet.microsoft 。 com / Forums / windowsserver / en-US / 16444c7a-ad61-44a7-8c6f-b8d619381a27 / using-icons-in-powershell-scripts?forum = winserverpowershell )做了类似的事情,并创build了一个新的脚本来满足我的需求。

我input的参数是(DLL文件中的源DLLpath,目标图标文件名和图标索引):

C:\ WINDOWS \ SYSTEM32 \ SHELL32.DLL

C:\ TEMP \ Restart.ico

238

通过临时创build一个新的快捷方式(右键单击桌面并selectNew – > Shortcut并inputcalc并按Enter两次),我发现我需要的图标索引是#238。 然后右键单击新的快捷方式并select“属性”,然后在“快捷方式”选项卡中单击“更改图标”button。 粘贴到pathC:\ Windows \ System32 \ shell32.dll中,然后单击确定。 find你想使用的图标,并找出其索引。 注意:索引2在#1之下,而不在右边。 图标索引#5在Windows 7 x64机器的第二列的顶部。

如果任何人有一个更好的方法,同样的作品,但获得更高质量的图标,那么我会有兴趣听到它。 谢谢,肖恩。

#Windows PowerShell Code########################################################################### # http://gallery.technet.microsoft.com/scriptcenter/Icon-Exporter-e372fe70 # # AUTHOR: John Grenfell # ########################################################################### <# .SYNOPSIS Exports an ico and bmp file from a given source to a given destination .Description You need to set the Source and Destination locations. First version of a script, I found other examples but all I wanted to do as grab and ico file from an exe but found getting a bmp useful. Others might find useful No error checking I'm afraid so make sure your source and destination locations exist! .EXAMPLE .\Icon_Exporter.ps1 .Notes Version HISTORY: 1.1 2012.03.8 #> Param ( [parameter(Mandatory = $true)][string] $SourceEXEFilePath, [parameter(Mandatory = $true)][string] $TargetIconFilePath ) CLS #"shell32.dll" 238 If ($SourceEXEFilePath.ToLower().Contains(".dll")) { $IconIndexNo = Read-Host "Enter the icon index: " $Icon = [System.IconExtractor]::Extract($SourceEXEFilePath, $IconIndexNo, $true) } Else { [void][Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $image = [System.Drawing.Icon]::ExtractAssociatedIcon("$($SourceEXEFilePath)").ToBitmap() $bitmap = new-object System.Drawing.Bitmap $image $bitmap.SetResolution(72,72) $icon = [System.Drawing.Icon]::FromHandle($bitmap.GetHicon()) } $stream = [System.IO.File]::OpenWrite("$($TargetIconFilePath)") $icon.save($stream) $stream.close() Write-Host "Icon file can be found at $TargetIconFilePath" 

资源提取是另一个工具,将recursion地查找很多DLL的图标,非常方便的IMO。

您可以下载免费资源黑客 ,然后按照下面的说明:

  1. 打开您想要查找图标的任何dll文件。
  2. 浏览文件夹以查找特定的图标。
  3. 从菜单栏中select“操作”,然后select“保存”。
  4. select.ico文件的目的地。

参考: http : //techsultan.com/how-to-extract-icons-from-windows-7/

以上是上述解决scheme的更新版本。 我添加了一个被遗忘在一个链接中的组件。 新手不会理解这一点。 这是样本将运行没有修改。

  <# .SYNOPSIS Exports an ico and bmp file from a given source to a given destination .Description You need to set the Source and Destination locations. First version of a script, I found other examples but all I wanted to do as grab and ico file from an exe but found getting a bmp useful. Others might find useful .EXAMPLE This will run but will nag you for input .\Icon_Exporter.ps1 .EXAMPLE this will default to shell32.dll automatically for -SourceEXEFilePath .\Icon_Exporter.ps1 -TargetIconFilePath 'C:\temp\Myicon.ico' -IconIndexNo 238 .EXAMPLE This will give you a green tree icon (press F5 for windows to refresh Windows explorer) .\Icon_Exporter.ps1 -SourceEXEFilePath 'C:/Windows/system32/shell32.dll' -TargetIconFilePath 'C:\temp\Myicon.ico' -IconIndexNo 41 .Notes Based on http://stackoverflow.com/questions/8435/how-do-you-get-the-icons-out-of-shell32-dll Version 1.1 2012.03.8 New version: Version 1.2 2015.11.20 (Added missing custom assembly and some error checking for novices) #> Param ( [parameter(Mandatory = $true)] [string] $SourceEXEFilePath = 'C:/Windows/system32/shell32.dll', [parameter(Mandatory = $true)] [string] $TargetIconFilePath, [parameter(Mandatory = $False)] [Int32]$IconIndexNo = 0 ) #https://social.technet.microsoft.com/Forums/windowsserver/en-US/16444c7a-ad61-44a7-8c6f-b8d619381a27/using-icons-in-powershell-scripts?forum=winserverpowershell $code = @" using System; using System.Drawing; using System.Runtime.InteropServices; namespace System { public class IconExtractor { public static Icon Extract(string file, int number, bool largeIcon) { IntPtr large; IntPtr small; ExtractIconEx(file, number, out large, out small, 1); try { return Icon.FromHandle(largeIcon ? large : small); } catch { return null; } } [DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] private static extern int ExtractIconEx(string sFile, int iIndex, out IntPtr piLargeVersion, out IntPtr piSmallVersion, int amountIcons); } } "@ If (-not (Test-path -Path $SourceEXEFilePath -ErrorAction SilentlyContinue ) ) { Throw "Source file [$SourceEXEFilePath] does not exist!" } [String]$TargetIconFilefolder = [System.IO.Path]::GetDirectoryName($TargetIconFilePath) If (-not (Test-path -Path $TargetIconFilefolder -ErrorAction SilentlyContinue ) ) { Throw "Target folder [$TargetIconFilefolder] does not exist!" } Try { If ($SourceEXEFilePath.ToLower().Contains(".dll")) { Add-Type -TypeDefinition $code -ReferencedAssemblies System.Drawing $form = New-Object System.Windows.Forms.Form $Icon = [System.IconExtractor]::Extract($SourceEXEFilePath, $IconIndexNo, $true) } Else { [void][Reflection.Assembly]::LoadWithPartialName("System.Drawing") [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") $image = [System.Drawing.Icon]::ExtractAssociatedIcon("$($SourceEXEFilePath)").ToBitmap() $bitmap = new-object System.Drawing.Bitmap $image $bitmap.SetResolution(72,72) $icon = [System.Drawing.Icon]::FromHandle($bitmap.GetHicon()) } } Catch { Throw "Error extracting ICO file" } Try { $stream = [System.IO.File]::OpenWrite("$($TargetIconFilePath)") $icon.save($stream) $stream.close() } Catch { Throw "Error saving ICO file [$TargetIconFilePath]" } Write-Host "Icon file can be found at [$TargetIconFilePath]" 

只需用IrfanView打开DLL并将结果保存为.gif或.jpg。

我知道这个问题是旧的,但它是从“提取图标从DLL”的第二次谷歌命中,我想避免在我的工作站上安装任何东西,我记得我使用IrfanView。

如果您使用的是Linux,则可以使用gExtractWinIcons从Windows DLL中提取图标。 它在Ubuntu和Debian中的gextractwinicons软件包中可用。

这个博客文章有一个截图和简单的解释 。

还有这个资源,Visual Studio图像库,“可以用来创build应用程序,看起来与Microsoft软件看起来一致”,大概是根据底部授予的许可。 https://www.microsoft.com/en-ca/download/details.aspx?id=35825