How to change an ID number in an exe file without recompiling it

Posted on 2005-04-26
Last Modified: 2010-05-18

it was not easy to find an appropriate title for my question. I'll try to explain my problem as clear as possible.
I have to write a small application, which does set a special bit in the memory of a hardware device. I already have the application which sets the bit, BUT this bit may not be set in every device. Only devices with a special hardware ID may have set this bit.
The problem is, that the hardware IDs which may have set this bit are not known at compliling time. The valid hardware ID has to be set in the application later.
This bit is for some kind of security reason. Therefore it is important that the hardware ID can not be chosen by anyone, so that the bit can not be set in any device (no *.ini file).
This change in the application must be possible on every computer, even if there is no compiler installed.

Is there some possibility of having a small standalone compiler or something like this? Any other ideas?

I hope I made myself clear enough... Otherwise just ask.

Thank you very much
Question by:Bohne
    LVL 55

    Expert Comment

    by:Jaime Olivares
    I think best approach is to save ID as a resource (like a bitmap or icon inside your app), so you can change it without recompiling.
    Is your app a Windows GUI application?

    Author Comment

    yes it's a MFC GUI application in Visual Studio C++. How do I get this resource into my application? And is it secure, can nobody else change this resource?
    LVL 55

    Expert Comment

    by:Jaime Olivares
    >>And is it secure, can nobody else change this resource?
    There doesn't exist a secure method by itself, anybody can change your app and you can't avoid it in any way, but you can encrypt your data so if other user try to change it, you can detect it with some kind of CRC or hash algorithm.

    Author Comment

    So how do I change this resource? Can I write a small second application which changes the resource?

    Author Comment

    I have now stored the ID in the String Table resource of my application. So I can change this string (e.g. with Resource Hacker) and everything works. But how do I change this string with a self programmed tool (which should be much more simple than Resource Hacker)? Are there any examples on changing a resource of an exe file in Visual Studio C++?
    LVL 55

    Accepted Solution

    It is something like this (not tested):

    BOOL UpdateTextRes(LPCTSTR filename, LPCTSTR resname, LPCTSTR str)   // Tip: use upercase for all strings
          HANDLE hRes = ::BeginUpdateResource(filename, FALSE);
          if (!hRes) {
              ::AfxMessageBox("Error opening file");
          } else {
              BOOL result = ::UpdateResource(hRes, RT_RCDATA, resname, 0, str, strlen(str));  // notice resource type: RCDATA
              ::EndUpdateResource(hRes, !result);
          return result;   // returns true if sucessfully updated

    more information at:

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now