图标已被Powershell exe到ico转换器损坏

图标已被Powershell exe到ico转换器损坏,powershell,icons,executable,converters,ico,Powershell,Icons,Executable,Converters,Ico,我正在寻找一个powershell脚本来提取可执行文件的.ico 我发现了一些像这样的工具: [System.Reflection.Assembly]::LoadWithPartialName('System.Drawing') | Out-Null $folder = "C:\TMP_7423\icons" md $folder -ea 0 | Out-Null dir $env:windir *.exe -ea 0 -rec | ForEach-Object { $bas

我正在寻找一个powershell脚本来提取可执行文件的.ico

我发现了一些像这样的工具:

[System.Reflection.Assembly]::LoadWithPartialName('System.Drawing')  | Out-Null

$folder = "C:\TMP_7423\icons"
md $folder -ea 0 | Out-Null

dir $env:windir *.exe -ea 0 -rec |
  ForEach-Object { 
    $baseName = [System.IO.Path]::GetFileNameWithoutExtension($_.FullName)
    Write-Progress "Extracting Icon" $baseName
    [System.Drawing.Icon]::ExtractAssociatedIcon($_.FullName).ToBitmap().Save("$folder\$BaseName.ico")
}
但问题是,我想为另一个工具使用powershell到exe的转换器,该工具具有直接在生成的.exe中放置图标的功能。我想对生成的可执行文件使用提取的ico。 问题是ps1到exe转换器不能与ico提取器生成的任何图标一起工作。 但是,问题是,当我使用我在互联网上找到的.ico时,ps1到exe转换器可以工作

那么,您是否有任何可执行的.ico提取器,它不提取损坏的ico,但可以在internet上找到正常的.ico


先谢谢你!:)

我使用Windows窗体编写了一个Powershell实用程序,正是出于这个目的:


此处提供:

可能ps1到exe转换器需要正确的.ICO,并且您的代码使用
ToBitmap().Save()
,这将不会以ICO格式保存图像信息。为此,需要使用提取图标本身的
Save()
方法

不幸的是,此保存方法的参数只能是流对象,而不仅仅是路径

尝试:


感谢您的支持,但我正在寻找一个类似命令行的工具。你的工具有这个功能吗?谢谢!是的,它起到了作用,你节省了数小时的搜索时间(dud:)@PrivateZkAw我添加了
$ico.Dispose()
以保持整洁;)
Add-Type -AssemblyName System.Drawing

$folder = "C:\TMP_7423\icons"
if (!(Test-Path -Path $folder -PathType Container)) {
    $null = New-Item -Path $folder -ItemType Directory
}
Get-ChildItem -Path $env:windir -Filter '*.exe' -Recurse |
  ForEach-Object { 
    Write-Progress "Extracting Icon $($_.BaseName)"
    $ico = [System.Drawing.Icon]::ExtractAssociatedIcon($_.FullName)
    $target = Join-Path -Path $folder -ChildPath ('{0}.ico' -f $_.BaseName)
    # create a filestream object
    $stream = [System.IO.FileStream]::new($target, [IO.FileMode]::Create, [IO.FileAccess]::Write)
    # save as ICO format to the filestream
    $ico.Save($stream)
    # remove the stream object
    $stream.Dispose()
    $ico.Dispose()
}