windows 你如何从 shell32.dll 中获取图标?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you get the icons out of shell32.dll?
提问by Jay Mooney
I'd like to get the Tree icon to use for a homegrown app. Does anyone know how to extract the images out as .icon files? I'd like both the 16x16 and 32x32, or I'd just do a screen capture.
我想让树图标用于本土应用程序。有谁知道如何将图像提取为 .icon 文件?我想要 16x16 和 32x32,或者我只是做一个屏幕截图。
采纳答案by jm.
In Visual Studio, choose "File Open..." then "File...". Then pick the Shell32.dll. A folder tree should be opened, and you will find the icons in the "Icon" folder.
在 Visual Studio 中,选择“文件打开...”,然后选择“文件...”。然后选择Shell32.dll。应打开文件夹树,您将在“图标”文件夹中找到图标。
To save an Icon, you can right-click on the icon in the folder tree and choose "Export".
要保存图标,您可以右键单击文件夹树中的图标并选择“导出”。
回答by AQN
If anyone is seeking an easy way, just use 7zip to unzip the shell32.dll and look for the folder .src/ICON/
如果有人正在寻找一种简单的方法,只需使用 7zip 解压缩 shell32.dll 并查找文件夹 .src/ICON/
回答by OJ.
Another option is to use a tool such as ResourceHacker. It handles way more than just icons as well. Cheers!
另一种选择是使用诸如ResourceHacker 之类的工具。它处理的不仅仅是图标。干杯!
回答by Shaun
I needed to extract icon #238 from shell32.dll and didn't want to download Visual Studio or Resourcehacker, so I found a couple of PowerShell scripts from Technet (thanks John Grenfell and to #https://social.technet.microsoft.com/Forums/windowsserver/en-US/16444c7a-ad61-44a7-8c6f-b8d619381a27/using-icons-in-powershell-scripts?forum=winserverpowershell) that did something similar and created a new script (below) to suit my needs.
我需要从 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)做了类似的事情并创建了一个新脚本(如下)以满足我的需要.
The parameters I entered were (the source DLL path, target icon file name and the icon index within the DLL file):
我输入的参数是(源DLL路径、目标图标文件名和DLL文件中的图标索引):
C:\Windows\System32\shell32.dll
C:\Windows\System32\shell32.dll
C:\Temp\Restart.ico
C:\Temp\Restart.ico
238
238
I discovered the icon index that I needed was #238 by trial and error by temporarily creating a new shortcut (right-click on your desktop and select New --> Shortcut and type in calc and press Enter twice). Then right-click the new shortcut and select Properties then click 'Change Icon' button in the Shortcut tab. Paste in path C:\Windows\System32\shell32.dll and click OK. Find the icon you wish to use and work out its index. NB: Index #2 is beneath #1 and not to its right. Icon index #5 was at the top of column two on my Windows 7 x64 machine.
我发现我需要的图标索引是#238,通过临时创建一个新的快捷方式(右键单击您的桌面并选择新建 --> 快捷方式并输入 calc 并按两次 Enter 键),通过反复试验发现我需要的图标索引是 #238。然后右键单击新的快捷方式并选择“属性”,然后单击“快捷方式”选项卡中的“更改图标”按钮。粘贴到路径 C:\Windows\System32\shell32.dll 中,然后单击“确定”。找到您要使用的图标并计算其索引。注意:索引#2 位于#1 下方而不是其右侧。图标索引 #5 在我的 Windows 7 x64 机器上位于第二列的顶部。
If anyone has a better method that works similarly but obtains higher quality icons then I'd be interested to hear about it. Thanks, Shaun.
如果有人有更好的方法可以类似地工作但获得更高质量的图标,那么我很想听听它。谢谢,肖恩。
#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"
回答by Steve Cadwallader
Resources Extractis another tool that will recursively find icons from a lot of DLLs, very handy IMO.
Resources Extract是另一种工具,可以从大量 DLL 中递归查找图标,非常方便 IMO。
回答by Mr. Annoyed
Here is an updated version of a solution above. I added a missing assembly that was buried in a link. Novices will not understand that. This is sample will run without modifications.
这是上述解决方案的更新版本。我添加了一个隐藏在链接中的缺失程序集。新手不会明白这一点。这是示例将无需修改即可运行。
<#
.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]"
回答by MannyO
Just open the DLL with IrfanView and save the result as a .gif or .jpg.
只需使用 IrfanView 打开 DLL 并将结果保存为 .gif 或 .jpg。
I know this question is old, but it's the second google hit from "extract icon from dll", I wanted to avoid installing anything on my workstation and I remembered I use IrfanView.
我知道这个问题很老,但它是“从 dll 中提取图标”的第二个谷歌点击,我想避免在我的工作站上安装任何东西,我记得我使用 IrfanView。
回答by JohnOconor
You can download freeware Resource Hackerand then follow below instructions :
您可以下载免费软件Resource Hacker,然后按照以下说明操作:
- Open any dll file you wish to find icons from.
- Browse folders to find specific icons.
- From menu bar, select 'action' and then 'save'.
- Select destination for .ico file.
- 打开您希望从中查找图标的任何 dll 文件。
- 浏览文件夹以查找特定图标。
- 从菜单栏中,选择“操作”,然后选择“保存”。
- 选择 .ico 文件的目的地。
Reference : http://techsultan.com/how-to-extract-icons-from-windows-7/
参考:http: //techsultan.com/how-to-extract-icons-from-windows-7/
回答by Smylers
If you're on Linux, you can extract icons from a Windows DLL with gExtractWinIcons.
It's available in Ubuntu and Debian in the gextractwinicons
package.
如果您使用的是 Linux,则可以使用gExtractWinIcons从 Windows DLL 中提取图标。它在软件包中的 Ubuntu 和 Debian 中可用gextractwinicons
。
This blog article has a screenshot and brief explanation.
这篇博客文章有截图和简要说明。
回答by David Carr
There is also this resource available, the Visual Studio Image Library, which "can be used to create applications that look visually consistent with Microsoft software", presumably subject to the licensing given at the bottom. https://www.microsoft.com/en-ca/download/details.aspx?id=35825
还有一个可用的资源,Visual Studio Image Library,它“可用于创建看起来与 Microsoft 软件在视觉上一致的应用程序”,大概受底部给出的许可的约束。 https://www.microsoft.com/en-ca/download/details.aspx?id=35825