Jump to content

Save exe's icon to ico file


 Share

Recommended Posts

after some testing and with ICL returning unendless errors im trying to extract an exe's icon to an icon file

thats where i got so far but for a reason it creates an empty file if u have any other ways plz post them

thanks for the help

#include <GDIPlus.au3>

$filename = @ScriptDir & "\f.exe"
$iconnumber = 0 ;
;;

$Ret = DllCall("shell32","long","ExtractAssociatedIcon","int",0,"str",$filename,"int*",$iconnumber)
$hIcon = $Ret[0]
_GDIPlus_Startup()
        $pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromHICON", "ptr",$hIcon, "int*",0)
        $pBitmap = $pBitmap[2]
$CLSID = _GDIPlus_EncodersGetCLSID("ICO")
_GDIPlus_ImageSaveToFileEx($pBitmap, @ScriptDir & "\cool.ico", $CLSID)
_GDIPlus_ImageDispose($pBitmap)
_GDIPlus_Shutdown()
_WinAPI_DestroyIcon($Ret[0])
Link to comment
Share on other sites

GDI+ can't save to icon files.

After some extensive googling, I found these links, which should provide the answer, I think.

http://msdn.microsoft.com/en-us/library/ms997538.aspx

http://www.experts-exchange.com/Programmin...Q_10178834.html

http://www.experts-exchange.com/Programmin...Q_20658160.html

If you didn't know, expert exchange's answers can be read just by scrolling down..

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

thanks for the fast replay monoceres

i dont have an expert exchange account ...

the point im missing is i can get the icon with this call :

DllCall("shell32","long","ExtractAssociatedIcon","int",0,"str",$filename,"int*",$iconnumber)

but saving it to an ico file thats my problem

btw i already saw the msdn page

Link to comment
Share on other sites

im not very experienced with DLLs or GDI+.. or WINAPI... but COULD THIS WORK?

$x=DllCall("shell32","long","ExtractAssociatedIcon","int",0,"str",$filename,"int*",$iconnumber)

lol... would the variable get the STATUS of it? or the icon..

Link to comment
Share on other sites

i dont have an expert exchange account ...

Just scroll down the page, all the way down. You don't need an account..

but saving it to an ico file thats my problem

btw i already saw the msdn page

I think the EE links takes care on that.

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

thanks for responding again

"View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done."

and nothing else in the page

i did a work around and it wasnt a total failure

#include <GDIPlus.au3>
#include <IconChooser.au3>

$Icon = _ChooseIcon()
If $Icon[0] = "" Then Exit MsgBox(0, 'Exit', "No Icon chosen")
$Ret = DllCall("shell32","long","ExtractAssociatedIcon","int",0,"str",$Icon[0],"int*",(-1*$Icon[1])-1)
$hIcon = $Ret[0]
_GDIPlus_Startup()
        $pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromHICON", "ptr",$hIcon, "int*",0)
        $pBitmap = $pBitmap[2]
_GDIPlus_ImageSaveToFile($pBitmap,"D:\Test.png")
_GDIPlus_ImageDispose($pBitmap)
_GDIPlus_Shutdown()
_WinAPI_DestroyIcon($Ret[0])

and after creating the png i used another function to convert it to ico but the icon was like pixeled and looking ugly ...

Edited by yehia
Link to comment
Share on other sites

  • 10 months later...

Hey everybody,

I have the same problem and found the solution with this function :

Func _ExtractIconFromExe($source,$outsource,$iconnumber = 0)

$Ret = DllCall("shell32","long","ExtractAssociatedIcon","int",0,"str",$source,"int*",$iconnumber)
$hIcon = $Ret[0]
_GDIPlus_Startup()
        $pBitmapdll = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromHICON", "ptr",$hIcon, "int*",0)
        $pBitmap = $pBitmapdll[2]

_WinAPI_DestroyIcon($Ret[0])

_GDIPlus_ImageSaveToFileEx($pBitmap,$outsource, "{557CF400-1A04-11D3-9A73-0000F81EF32E}")

_GDIPlus_ImageDispose($pBitmap)

_GDIPlus_Shutdown()
Endfunc

You choose icon number if you want !

Edited by Vier
Link to comment
Share on other sites

Hey everybody,

I have the same problem and found the solution with this function :

Func _ExtractIconFromExe($source,$outsource,$iconnumber = 0)

$Ret = DllCall("shell32","long","ExtractAssociatedIcon","int",0,"str",$source,"int*",$iconnumber)
$hIcon = $Ret[0]
_GDIPlus_Startup()
        $pBitmapdll = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromHICON", "ptr",$hIcon, "int*",0)
        $pBitmap = $pBitmapdll[2]

_WinAPI_DestroyIcon($Ret[0])

_GDIPlus_ImageSaveToFileEx($pBitmap,$outsource, "{557CF400-1A04-11D3-9A73-0000F81EF32E}")

_GDIPlus_ImageDispose($pBitmap)

_GDIPlus_Shutdown()
Endfunc

You choose icon number if you want !

I tried this - exactly what I'm looking for - but it failed at $pBitmapdll. I tried declaring Local $pBitmapdll[100] but it didn't make a difference. I tested it on two .exes and on shell32.dll.

D:\Brian\autoit\5.au3 (19) : ==> Subscript used with non-Array variable.:

$pBitmap = $pBitmapdll[2]

$pBitmap = $pBitmapdll^ ERROR

The value for $pBitmapdll was 0. $hIcon has a value, so it's the DllCall that's not returning the expected array. Any ideas?
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...