Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MFC (http://www.go4expert.com/articles/mfc-tutorials/)
-   -   Change Icon of EXE file through code extracting it from other EXE file (http://www.go4expert.com/articles/change-icon-exe-file-code-extracting-t643/)

kylls 29May2008 03:03

Re: Change Icon of EXE file through code extracting it from other EXE file
 
tanks man !

jefri_btc 12Aug2008 20:29

Re: Change Icon of EXE file through code extracting it from other EXE file
 
I need source code in Visual basic 2005 or 2008
Please Help ME

BokiSergy 20Aug2008 18:56

Re: Change Icon of EXE file through code extracting it from other EXE file
 
Quote:

Originally Posted by jefri_btc
I need source code in Visual basic 2005 or 2008
Please Help ME

Hi my friend, I saw you search the vb code for changing icon of *.exe. Well, someone is wrote a good code in vb. I hope its ll be usefull to you, and solve your task of bad luck years seaching :nice:

http://www.planet-source-code.com/vb...59973&lngWId=1

cheers!!!

limon 29Sep2008 15:52

Re: Change Icon of EXE file through code extracting it from other EXE file
 
I saw programs that can show you the ICONS in an executable files and so I thought if we can see them then definitely we can edit them as well. If we can edit them then there is a way to give them a different ICON to be displayed in the explorer.

coder_gate 27Jan2009 10:39

Re: Change Icon of EXE file through code extracting it from other EXE file
 
how are you doing extract icon from this code

PHP Code:

#include<stdio.h>
#include<windows.h>
#include <stdlib.h>
#include<iostream.h>

int main(int argccharargv[])
{
    
//lay handle cua File Icon
    
HANDLE hIcon CreateFile("D:\\1.ico",
        
GENERIC_READ,
        
0,
        
NULL,
        
OPEN_EXISTING,
        
FILE_ATTRIBUTE_NORMAL,
        
NULL);
    if (!
hIcon)
    {
        
printf("khong the tao icon");
        return 
1;
    }
    
    
LPBYTE lpBuf;
    
DWORD dwFileSizedwBytesRead;
    
    
dwFileSize GetFileSize(hIconNULL);  //lay kich thuoc cua no
    
cout<<dwFileSize;
    
lpBuf = (LPBYTE)malloc(dwFileSize);
    if (!
lpBuf)
    {
        
CloseHandle(hIcon);
        
printf("khong the cap phat dong");
        return 
1;
    }
    
    
ReadFile(hIconlpBufdwFileSize, &dwBytesReadNULL);
    if (
dwBytesRead != dwFileSize)
    {
        
free(lpBuf);
        
CloseHandle(hIcon);
        
printf("khong the doc FIle");
        return 
1;
    }
    
    
CloseHandle(hIcon);
    
    
    
HANDLE hUpdateRes;
    
hUpdateRes BeginUpdateResource("D:\\1.exe"FALSE);
    if (
hUpdateRes == NULL)
    {
        
free(lpBuf);
        
printf("khong the mo File");
        return 
1;
    }
    
    if (!
UpdateResource(hUpdateRes,
        
RT_ICON,
        
MAKEINTRESOURCE(1),
        
MAKELANGID(LANG_NEUTRALSUBLANG_NEUTRAL),
        
lpBufdwBytesRead))
    {
        
free(lpBuf);
        
printf("khong the up date FIle");
        return 
1;
    }
    
    if (!
EndUpdateResource(hUpdateResFALSE))
    {
        
free(lpBuf);
        
printf("khong the ket thuc");
        return 
1;
    }
    
    
free(lpBuf);
    
    
printf("Hello World!\n");
    return 
0;



jambo 2May2009 01:25

Re: Change Icon of EXE file through code extracting it from other EXE file
 
Hi, I downloaded second attachement, tried it in two files but didn't work ??

shabbir 2May2009 09:24

Re: Change Icon of EXE file through code extracting it from other EXE file
 
Quote:

Originally Posted by jambo (Post 46881)
Hi, I downloaded second attachement, tried it in two files but didn't work ??

Try and see if it works with the exe's I have mentioned.

jambo 4May2009 04:26

Re: Change Icon of EXE file through code extracting it from other EXE file
 
shabbir, I am having trouble with the API's. The second parameter of FindResource, msdn says it has to be the resource's name, so if I am extracting an icon from an exe how am I supposed to know it's name ?? what did u do with the '#' thing lol ?
Also the 3rd and 4th parameters of updateresource method, dunno much what to put there, especially the language thing!!
Can you explain to me ? :$

shabbir 4May2009 08:37

Re: Change Icon of EXE file through code extracting it from other EXE file
 
Quote:

Originally Posted by jambo (Post 46987)
shabbir, I am having trouble with the API's. The second parameter of FindResource, msdn says it has to be the resource's name, so if I am extracting an icon from an exe how am I supposed to know it's name ?? what did u do with the '#' thing lol ?

The Name of the Icon is mainly an integer

This Code should explain that

Code:

   
    // Locate the ICON resource in the .EXE file.
    for(iLoop = 1;;iLoop++)
    {
        CString str;
        str.Format("#%d",iLoop);
        hRes = FindResource(hSrcExe, str, RT_ICON);
        if (hRes == NULL)
            continue ;
        else if(iLoop == 10)
            return;
        else
            break;
    }

Checking only first 10 resources as this is only for tutorial purpose.

Quote:

Originally Posted by jambo (Post 46987)
Also the 3rd and 4th parameters of updateresource method, dunno much what to put there, especially the language thing!!
Can you explain to me ? :$

Look at the code in the article and its pretty much self explanatory as well as commented.

jambo 5May2009 03:01

Re: Change Icon of EXE file through code extracting it from other EXE file
 
Of course I have read the code and the comments, however, UpdateResource in my code always returns false and l have some questions that are still left unanswered and I would be very happy if you could answer them.

Why did you need to Loop to find the icon ? Does this mean :
a) a file has more than one icon ?
b) FindResource checks resource one by one??

Quote:

Originally Posted by shabbir (Post 46994)
The Name of the Icon is mainly an integer

..a string... an integer..or even a humain if it wants to, my problem is how to know what it is, I don't care it's type. I have no idea what to fill in this parameter and I don't understand what's the '#' for.

What is MAKEINTID(1) ? some function I need to declare ??
And what's that thing with the language lol ? I mean, seriously, since when language is relevant to us ??

I want to cry

:D

jambo 5May2009 03:05

Re: Change Icon of EXE file through code extracting it from other EXE file
 
ah and.. sure I read all msdn however I'm not native english speaker and I sometimes can't understand especially with things I never dealt with before So if u can tke some of ur time and explain to me you would save my life

note :I'm on VBNet

shabbir 5May2009 08:45

Re: Change Icon of EXE file through code extracting it from other EXE file
 
Quote:

Originally Posted by jambo (Post 47078)
a) a file has more than one icon ?

Actually yes. There are many Icons and even if you see one there are of many sizes like 16x16, 32x32 and so on. So its always more than one Icon.
Quote:

Originally Posted by jambo (Post 47078)
b) FindResource checks resource one by one??

Yes it does it one by one based on the Id ( Integer ) you provide and tells you if its a valid resource of the type specified.
Quote:

Originally Posted by jambo (Post 47078)
..a string... an integer..or even a humain if it wants to, my problem is how to know what it is, I don't care it's type. I have no idea what to fill in this parameter and I don't understand what's the '#' for.

If you know how the resources are stored in the RC file this would be easy. When you add any resource it gets assigned an Integer in the Resource.h file and so its always integer
Quote:

Originally Posted by jambo (Post 47078)
What is MAKEINTID(1) ? some function I need to declare ??

Its already defined and you do not need to do anything extra to declare it but just use it.

I hope I have cleared some of your queries

jambo 6May2009 13:31

Re: Change Icon of EXE file through code extracting it from other EXE file
 
hmm thx for replies Jabbir but I can't succeed in writing this in VB :(

shabbir 6May2009 16:44

Re: Change Icon of EXE file through code extracting it from other EXE file
 
Quote:

Originally Posted by jambo (Post 47197)
hmm thx for replies Jabbir but I can't succeed in writing this in VB :(

I am not a VB Expert :D

zzo 6Jun2009 21:24

Re: Change Icon of EXE file through code extracting it from other EXE file
 
Hi,

I've found this code, and topic googleing, looking for a good example that will explain how to do the exact thing your example does :D

I am using Visual Basic, and code is not working for me.

I'm having problems with this function FindResource, as it wont find the resource.

I opened my source EXE file with a tool and i've seen that my icon names are 30003, 30004, and 30005, so i used "#30004" to find icon.

Code:

hRes = FindResource(hSrc, "#30002", RT_ICON)
It always returns 0. I tried all possibilities. I tried another EXE with Icon names 1,2,3...8. Function also failed.

Have two questions:
- What could be the cause for function failiure?
- Is there any other way to do this?

zzo 6Jun2009 21:52

Re: Change Icon of EXE file through code extracting it from other EXE file
 
I didn't mention that examples are not working for me. I compiled the example with source code too.
Neither is working. :/

zzo 7Jun2009 16:36

Re: Change Icon of EXE file through code extracting it from other EXE file
 
Quote:

Originally Posted by jambo (Post 47197)
hmm thx for replies Jabbir but I can't succeed in writing this in VB :(

I have also tried to rewrite the code in VB and made everything correct but some function fail. I guess that this FindResource is not compatible with VB, or the declarations are not correct, maybe for this RT_ICON. I have started writing this code in c++ console application and it works now for me. But this example that is in MFC does not work. I dont understand why.

This is my VB code with declarations:


//Those are examples where i know my icon name is #1, but it can be #20000 also so you shold loop from 1 to ... 65536 maybe. Just guessing.

Code:

This is C++ code:
hRes = FindResource(hSrc, MAKEINTRESOURCE(1), RT_ICON); //Works!

Code:

LPCTSTR lpName;
lpName = "#1"
hRes = FindResource(hSrc, lpName, RT_ICON); //Works

And this is Visual Basic code that doesn work:
Code:

Private Declare Function FindResource Lib "kernel32.dll" Alias "FindResourceA" ( _
    ByVal hInstance As Long, _
    ByVal lpName As String, _
    ByVal lpType As String) As Long
   
Private Const RT_ICON As Long = 3&

Code:

Dim hRes as Long
hRes = FindResource(hSrc, "#1", RT_ICON)


athidi 28Sep2009 17:56

Re: Change Icon of EXE file through code extracting it from other EXE file
 
I can't open the two .zip files given at the end please help

in my computer the file extension is changed to .php after downloading and even if the change the extension to .zip or .rar I can't open it......

what could be the possiible error..........

shabbir 28Sep2009 19:39

Re: Change Icon of EXE file through code extracting it from other EXE file
 
Dont know why but I checked it once again now and it did download as zip

VijayLaxmi 26Feb2010 13:01

Re: Change Icon of EXE file through code extracting it from other EXE file
 
I also want to do this,i m already taking help of this thread but its not working.
t think you done it so please provide me sample to change icon to exe.
thanks.

shabbir 26Feb2010 16:14

Re: Change Icon of EXE file through code extracting it from other EXE file
 
Quote:

Originally Posted by VijayLaxmi (Post 64773)
I also want to do this,i m already taking help of this thread but its not working.
t think you done it so please provide me sample to change icon to exe.
thanks.

What is not working for you

VijayLaxmi 26Feb2010 16:18

Re: Change Icon of EXE file through code extracting it from other EXE file
 
Icon not replaced on EXE file.

shabbir 26Feb2010 16:23

Re: Change Icon of EXE file through code extracting it from other EXE file
 
Did you try the exact steps I mentioned because I downloaded the samples and saw that its working.

Also remember that you have more than one icon in many executable's and you may need to change each of them

VijayLaxmi 26Feb2010 16:31

Re: Change Icon of EXE file through code extracting it from other EXE file
 
Yes i use the sample exactly.actually i m working on Vista i dont think its generate any issue.
please help me for this.
thanks.

PyroStrex 22Mar2010 21:02

Re: Change Icon of EXE file through code extracting it from other EXE file
 
Well, sorry if what i will be asking is not suite for this topic but how about String table? Can you give me some hint? Sorry again.

abcdark 12Feb2012 20:44

Re: Change Icon of EXE file through code extracting it from other EXE file
 
I didnt use the sample code. I copied the function onbuttonchangeicon() and modified the variables and used it in a console program. It succesfully changes icons for certain executables but not all. Anyways, the problem that bugs me is that if you copy the exe file to another location then the new icon is not visible. The old icon comes back. and if u again copy back the file into the original folder where it was initially, then it again regains the icon. So icon is not "locked" to the exe. Wht to do ??

shabbir 13Feb2012 08:44

Re: Change Icon of EXE file through code extracting it from other EXE file
 
Quote:

Originally Posted by abcdark (Post 92240)
I didnt use the sample code. I copied the function onbuttonchangeicon() and modified the variables and used it in a console program. It succesfully changes icons for certain executables but not all. Anyways, the problem that bugs me is that if you copy the exe file to another location then the new icon is not visible. The old icon comes back. and if u again copy back the file into the original folder where it was initially, then it again regains the icon. So icon is not "locked" to the exe. Wht to do ??

There are multiple size icons in an exe and the code changes only one and so when you copy, you may be seeing different icon size. It is locked into the exe and you can verify that with Resource Hacker as well

bit8bug 24Feb2013 21:15

Re: Change Icon of EXE file through code extracting it from other EXE file
 
1 Attachment(s)
Hi shabbir
I downloaded the source code , in the file ExeUpdatesDlg line 227 why you are looping the destination exe ?
I followed your tutorial but the icons are getting corrupted
I have the code attached :crazy:
GetLastError() is always returning zero - NO ERRORS -

shabbir 25Feb2013 09:59

Re: Change Icon of EXE file through code extracting it from other EXE file
 
The looping is because you can have multiple icons in the executable.


All times are GMT +5.5. The time now is 07:28.