2008-08-12 28 views
36

Me gustaría que el ícono Tree se use para una aplicación de cosecha propia. ¿Alguien sabe cómo extraer las imágenes como archivos .icon? Me gustaría tanto el 16x16 como el 32x32, o simplemente haría una captura de pantalla.¿Cómo se obtienen los iconos de shell32.dll?

+6

Tenga en cuenta que hacer esto es una violación de la licencia. "Mientras el software se está ejecutando, puede usar, pero no compartir sus iconos, imágenes, sonidos y medios". –

Respuesta

37

En Visual Studio, seleccione "Abrir archivo ..." y luego "Archivo ...". A continuación, elija el Shell32.dll. Se debe abrir un árbol de carpetas y encontrará los iconos en la carpeta "Icono".

Para guardar un icono, puede hacer clic derecho sobre el icono del árbol de carpetas y seleccione "Exportar".

+1

cuando uso esto solo tengo este árbol de carpetas y todos los íconos enumerados pero sin una vista previa y los títulos no son tan útiles (1, 10, 1001, ...) ¿Hay alguna manera de obtener una vista previa o hacer realmente tiene que abrir todos los iconos? – Bagorolin

+4

@Bagorolin aquí hay una clave útil http://www.glennslayden.com/code/shell32_icons.jpg –

+0

** Nota ** para Googlers, esto parece que ya no funciona en ** VS2017 **, al igual que la ventana de detalles de excepción durante la depuración – MickyD

17

Otra opción es utilizar una herramienta como ResourceHacker. Maneja mucho más que solo iconos. ¡Aclamaciones!

+0

Traté de usar Resource Hacker, pero cada icono tiene 12 duplicados (con varios tamaños). – HighTechProgramming15

4

Resources Extract es otra herramienta que forma recursiva encontrará iconos de una gran cantidad de archivos DLL, muy práctico de la OMI.

1

Sólo tiene que abrir el archivo DLL con IrfanView y guardar el resultado como un .gif o .jpg.

Sé que esta pregunta es antigua, pero es el segundo hit de google de "extraer ícono de dll", quería evitar instalar algo en mi estación de trabajo y recordé que uso IrfanView.

6

que necesitaba para extraer el icono # 238 de shell32.dll y no quería descargar Visual Studio o ResourceHacker, por lo que me encontré con un par de scripts de PowerShell de Technet (gracias John Grenfell y al # https://social.technet.microsoft.com/Forums/windowsserver/en-US/16444c7a-ad61-44a7-8c6f-b8d619381a27/using-icons-in-powershell-scripts?forum=winserverpowershell) que hizo algo similar y creó un nuevo guión (a continuación) para satisfacer mis necesidades.

Los parámetros que ha entrado no son (la ruta DLL fuente, nombre de archivo icono de destino y el índice de icono dentro del archivo DLL):

C: \ Windows \ System32 \ shell32.dll

C: \ temp \ Restart.ico

descubrí el índice de icono que necesitaba era # 238 por ensayo y error al crear temporalmente un nuevo acceso directo (clic derecho en el escritorio y seleccione nuevo -> Acceso directo y escriba calc y presione Enter dos veces). A continuación, haga clic con el botón derecho en el nuevo acceso directo y seleccione Propiedades, luego haga clic en el botón "Cambiar icono" en la pestaña Acceso directo. Pegue en la ruta C: \ Windows \ System32 \ shell32.dll y haga clic en Aceptar. Encuentre el ícono que desea usar y resuelva su índice. NB: el índice n. ° 2 está debajo del n. ° 1 y no a la derecha.El índice de iconos # 5 estaba en la parte superior de la columna dos en mi máquina con Windows 7 x64.

Si alguien tiene un método mejor que funciona de manera similar pero obtiene iconos de mayor calidad, me interesaría saberlo. Gracias, 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" 
+0

Respuesta mucho más útil que el resto. – slashp

+0

Excelente método, pero no funciona para mí. Estoy en Windows 7x64 en el que el script parece estar confirmado para funcionar. Pero obtengo errores 'TypeNotFound' para' System.Drawing.Icon' y 'System.Drawing.Bitmap'. ¿Mi primer intento de ejecutar un script de PS así que tal vez hago algo mal? –

+0

Ok, solo necesitaba ejecutar 'Add-Type -AssemblyName System.Drawing' primero. –

2

Aquí hay una versión actualizada de una solución anterior. Agregué un ensamblaje faltante que estaba enterrado en un enlace. Los novatos no entenderán eso. Este es el ejemplo se ejecutará sin modificaciones.

<# 
.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

Si alguien está buscando una manera fácil, sólo tiene que utilizar 7zip para descomprimir el shell32.dll y buscar la carpeta .src/ICON/

+0

Sí, uso mucho la función 7-Zip "abrir archivo". – Niek

+0

No tengo 7Zip, pero probé esto en WinRAR y dice que no hay archivo para abrir. – Hashim

+0

cambie el nombre a shell32.7z y luego intente abrirlo con 7-zip, Peazip o sus otras herramientas de compresión favorita – ronaldwidha

1

Hay también disponible este recurso, el Visual Studio Image Library , que "se puede usar para crear aplicaciones que se vean visualmente consistentes con el software de Microsoft", presumiblemente sujeto a la licencia otorgada en la parte inferior. https://www.microsoft.com/en-ca/download/details.aspx?id=35825

Cuestiones relacionadas