2008-08-12 1072 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/