2008-08-12 1067 views
36

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

+6

请注意,这样做违反了许可证。 “软件运行时,您可以使用但不共享其图标,图像,声音和媒体。” – 2013-03-29 22:45:06

回答

37

在Visual Studio中,选择“文件打开...”,然后选择“文件...”。然后选择Shell32.dll。应打开文件夹树,并在“图标”文件夹中找到图标。

要保存图标,您可以右键单击文件夹树中的图标并选择“导出”。

+1

当我使用这个我只有这个文件夹树和列出的所有图标,但没有预览和标题是不是有帮助(1,10,1001,..)有没有一种方法来预览或我真的必须打开所有的图标? – Bagorolin 2015-07-23 10:46:30

+4

@Bagorolin这里是一个方便的钥匙http://www.glennslayden.com/code/shell32_icons.jpg – 2016-10-12 09:56:49

+0

**注意**给Google员工,这似乎不再适用** VS2017 **,就像异常详细信息窗口在调试过程中 – MickyD 2018-01-04 03:18:49

17

另一种选择是使用工具,如ResourceHacker。它处理方式不仅仅是图标。干杯!

+0

我尝试使用Resource Hacker,但每个图标都有12个重复项(具有各种大小)。 – HighTechProgramming15 2017-01-03 13:27:42

4

Resources Extract是另一种从递归查找很多DLL中的图标的工具,非常方便的IMO。

1

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

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

6

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

我输入的参数为(来源DLL的路径,目标图标文件名和DLL文件中的图标索引):

C:\ WINDOWS \ SYSTEM32 \ shell32.dll中

C:\ TEMP \ Restart.ico

我发现我需要的是通过试验和错误通过临时创建一个新的快捷方式#238图标指数(在桌面上单击鼠标右键,选择新建 - >快捷方式和键入calc并按Enter两次)。然后右键单击新的快捷方式并选择属性,然后在快捷方式选项卡中单击“更改图标”按钮。粘贴到路径C:\ Windows \ System32 \ shell32.dll中,然后单击确定。找到你想使用的图标并找出它的索引。注意:索引#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" 
2

这是以上解决方案的更新版本。 我添加了一个被隐藏在链接中的缺少的程序集。 新手不会理解这一点。 这是示例将运行没有修改。

<# 
.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]" 
20

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