Windows API - Set Version Information of Existing File

Posted on 2007-07-31
Last Modified: 2013-12-03
I need a way to set the version information of an existing file.  By version information I mean the information that is retrieved by a call to GetFileVersionInfo.

I have a component in my program to zip files into a cabinet (CAB) file.  I frequently release updates of my program and I need a way to find out which version of the program a particular CAB file was made with.  Unfortunately, the component that I use does not have an option to set the version information as it creates the file.

I can't find anything like a SetFileVersionInfo function in the API documentation and I'm not sure that what I'm trying to do is even possible.  The only other option that I can think of is to put the version number in the filename but I would like to avoid that as my users frequently rename their backups.

Thank you in advance for your responses!

Question by:AdrianSRU
    LVL 86

    Accepted Solution

    See ("Updating version information at run-time"). The scoop is to use 'UpdateResource()':

    HANDLE hResource = BeginUpdateResource(lpszFile, FALSE);
    if (NULL != hResource)
        UINT uTemp;

        // get the language information
        if (VerQueryValue(lpBuffer,
                          (LPVOID *) &lpTranslate,
                          &uTemp) != FALSE)
            // could probably just use LANG_NEUTRAL/SUBLANG_NEUTRAL
            if (UpdateResource(hResource,
                               dwSize) != FALSE)
                EndUpdateResource(hResource, FALSE);
    LVL 12

    Author Comment

    Thanks for your quick response.  Are those functions available in all versions of windows from 95 to Vista?

    LVL 86

    Expert Comment

    Yes, see ("UpdateResource Function") for the considerations regarding Win9x (which only affect the UNICODE versions of these APIs)

    Featured Post

    Javascript: Crash Course

    Javascript is not only emerging as the most important language to know, it's flexibility is unique. With Javascript being deployed on the web, mobile and even the desktop this is the one language that all technologists need to know.

    Join & Write a Comment

    Suggested Solutions

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    730 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

    17 Experts available now in Live!

    Get 1:1 Help Now