用 PowerShell 从 EXE 提取程序图标
使用容易被遗忘的 Icon.ExtractAssociatedIcon 方法,把可执行文件内嵌的图标导出为 PNG。
对 exe 路径调用 [System.Drawing.Icon]::ExtractAssociatedIcon,再用 ToBitmap() 转换并以 PNG 保存。
01命令
命令
$ Add-Type -AssemblyName System.Drawing; $ico=[System.Drawing.Icon]::ExtractAssociatedIcon('C:\Windows\System32\notepad.exe'); $ico.ToBitmap().Save('C:\temp\notepad-icon.png',[System.Drawing.Imaging.ImageFormat]::Png)02作用说明
Windows 把每个程序的图标内嵌在可执行文件里,ExtractAssociatedIcon 无需任何资源编辑器就能直接读取。该方法只返回 32x32 尺寸,要拿更大或多尺寸图标需解析原始资源,但对写文档、README 或快捷方式已足够。ToBitmap 会把它转换成普通图像,可保存为任意 GDI+ 格式。
03风险
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- Icon.ToBitmap Method (System.Drawing)依据: Documents converting the extracted Icon into a Bitmap so it can be saved as PNG or another image format.
- Icon.ExtractAssociatedIcon Method (System.Drawing)依据: Documents extracting the icon image contained in an executable file, and notes the returned icon is 32x32 pixels.
最后验证: 2026-09-17 · 分类: 媒体