• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1655
  • Last Modified:

Windows API - Set Version Information of Existing File

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!


--Adrian
0
AdrianSRU
Asked:
AdrianSRU
  • 2
1 Solution
 
jkrCommented:
See http://www.codeproject.com/samples/UpdateVersion.asp ("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,
                      _T("\\VarFileInfo\\Translation"),
                      (LPVOID *) &lpTranslate,
                      &uTemp) != FALSE)
    {
        // could probably just use LANG_NEUTRAL/SUBLANG_NEUTRAL
        if (UpdateResource(hResource,
                           RT_VERSION,
                           MAKEINTRESOURCE(VS_VERSION_INFO),
                           lpTranslate->wLanguage,
                           lpBuffer,
                           dwSize) != FALSE)
        {
            EndUpdateResource(hResource, FALSE);
        }
    }
}
0
 
AdrianSRUAuthor Commented:
Thanks for your quick response.  Are those functions available in all versions of windows from 95 to Vista?


--Adrian
0
 
jkrCommented:
Yes, see http://msdn2.microsoft.com/en-us/library/ms648049.aspx ("UpdateResource Function") for the considerations regarding Win9x (which only affect the UNICODE versions of these APIs)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now