Из документации ExtractIconExW:
Код: Выделить всё
UINT ExtractIconExW(
[in] LPCWSTR lpszFile,
[in] int nIconIndex,
[out] HICON *phiconLarge,
[out] HICON *phiconSmall,
UINT nIcons
);
Если это значение равно –1< /strong> и phiconLarge и phiconSmall имеют значения NULL, функция возвращает общее количество значков в указанном файле >. Если файл является исполняемым файлом или DLL, возвращаемое значение — это количество ресурсов RT_GROUP_ICON. Если файл представляет собой файл .ico, возвращаемое значение равно 1.
Поэтому я попытался сделать именно это с помощью следующего:
Код: Выделить всё
function get-icon-count {
Param (
[parameter(Mandatory = $true)] [string] $SourceFile = 'C:/Windows/system32/shell32.dll',
[parameter(Mandatory = $False)] [Int32] $IconIndex = 0 # -1: To count icons,
)
$code = @'
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.IO;
using System.Management.Automation;
namespace System {
public class FileIconInfo {
[DllImport("Shell32.dll", EntryPoint = "ExtractIconExW", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern int ExtractIconExW( string szFileName, int nIconIndex, out IntPtr phiconLarge, out IntPtr phiconSmall, uint nIcons);
}
}
'@
#@'
Add-Type -AssemblyName System.Drawing
$refAssemblies = @([Drawing.Icon].Assembly.Location) # C:\Program Files\PowerShell\7\System.Drawing.Common.dll
try {
Add-Type -TypeDefinition $code -PassThru -ReferencedAssemblies $refAssemblies #| Import-Module -Assembly { $_.Assembly }
$img = [System.FileIconInfo]::ExtractIconExW($SourceFile, -1, $null, $null, 1)
} Catch {
Write-Host -f Red "[ERROR] Failed in ExtractIconExW()!"
Write-Host -f Red "[ERROR] $_"
$_ | select *
Return
}
Write-Host -f DarkYellow "The number of icon indexes fund are: $([int32]$img)"
Return $([int32]$img)
}
Код: Выделить всё
. .\extract-icon.ps1 && get-icon-count 'C:\\shell32.dll'Код: Выделить всё
'C:\Windows\SystemResources\shell32.dll.mun'
'C:\Windows\SystemResources\imageres.dll.mun'
Код: Выделить всё
Argument: '3' should be a System.Management.Automation.PSReference. Use [ref].Как я могу исправить скрипт для получения количества значков в DLL/EXE?
Подробнее здесь: https://stackoverflow.com/questions/791 ... -powershel
Мобильная версия