2015-10-12 38 views
0

我现在可能需要您的帮助,我一直在谷歌搜索全部,但我确实没有得到真正的答案,所以我很平衡把我的问题这里。 如何获取.exe文件的图标并使用批处理代码保存到硬盘中? 感谢我怎样才能从exe文件中获取图标并通过批处理代码保存到驱动器

+0

没有内置的命令可以做这样的事情;你需要一些第三方工具 – aschipfl

+1

或者一个powershell脚本:[一个](https://community.spiceworks.com/topic/592770-extract-icon-from-exe-powershell),[two](http: //scriptolog.blogspot.com/2007/12/extracting-icons-with-powershell.html),[three](http://powershellscripter.com/2014/10/07/get-the-icon-of-a -exe-file /),[四](http://powershell.com/cs/blogs/tips/archive/2011/09/26/extracting-icons.aspx),[五](http:// www。 hican.net/2014/05/powershell-extract-icon-files-from-executables/) – wOxxOm

回答

1

扩展在wOxxOm以上建议,你可以用PowerShell命令批处理脚本这样的内做到这一点:

@echo off 
setlocal 

set "exe_in=%~1" 
set "ico_out=%~2" 

set "psCommand="[void][Reflection.Assembly]::LoadWithPartialName('System.Drawing');^ 
[Drawing.Icon]::ExtractAssociatedIcon(\"%exe_in%\").ToBitmap().Save(\"%ico_out%\")"" 

powershell -noprofile -noninteractive %psCommand% 

用法示例:

script.bat c:\portaputty\putty.exe putty.ico 

...会将putty.ico保存到当前工作目录。


或者,如果你想拥有的脚本保存到basename.ico,而你不必指定参数2,您可以美化有点像这样:

@echo off 
setlocal 

set "exe_in=%~1" 
set "out_dir=." 

if not "%~2"=="" 2>NUL pushd "%~2" && (call set "out_dir=%%CD%%" & popd) 
set "ico_out=%out_dir%\%~n1.ico" 

set "psCommand="[void][Reflection.Assembly]::LoadWithPartialName('System.Drawing');^ 
[Drawing.Icon]::ExtractAssociatedIcon(\"%exe_in%\").ToBitmap().Save(\"%ico_out%\")"" 

powershell -noprofile -noninteractive %psCommand% 

用法示例:

script.bat c:\portaputty\putty.exe 

...将putty.ico保存到当前工作目录。

script.bat c:\portaputty\putty.exe "%temp%" 

...将节省%temp%\ putty.ico。

相关问题