GetVers.exe Specifies Component FileVersion & #Version

ID: Q167597


The information in this article applies to:
  • Microsoft Internet Explorer (Programming) versions 3.0, 3.01, 3.02, 4.0


SUMMARY

Update of components over the Web is usually controlled by the component's file version. This file version can be specified either by the #Version in the CODEBASE attribute of the <OBJECT> tag or the FileVersion keyword in the .inf file. Determining the file version can be confusing, and if not specified correctly, could cause the component to download incorrectly. If you do not have access to Microsoft Developer Studio or an environment capable of opening file resources, you can use the file GetVers.exe to obtain the necessary version.


MORE INFORMATION

For the <OBJECT> tag, specify the file version using the CODEBASE attribute in this manner:


   <OBJECT ID="BoomButton" WIDTH=225 HEIGHT=35
   CLASSID="CLSID:56F1BF40-B2D0-11d0-A6D6-00AA00A70FC2"
   CODEBASE="http://example.microsoft.com/AControl.cab#Version=1,0,0,1">
   ... 
In pseudo-code, here's how component download is controlled for the <OBJECT> tag:

   Check the Registry for CLSID
   If CLSID of OBJECT is NOT found in the registry
      Download OBJECT
   Else If no #Version specified in CODEBASE tag
      Use OBJECT installed on system
   Else
      Check InprocServer32 key for location of installed component
      If File version of installed component < CODEBASE #Version Tag
         Download OBJECT 
There are a couple of exceptions to the above sequence. If an [AppID] key is found under the CLSID, the component is usually registered to run via DCOM and is not updated. Also, an [Installed Version] key takes precedence over the file version. This is used for Java classes and non PE (portable executable) files.

Update of components installed via an .inf file is controlled by the FileVersion keyword in the .inf file. For example, the following syntax controls the installation of mfc42.dll for the VC 4.2b control above:

   [mfc42.dll]
   FileVersion=4,2,0,6256
   hook=mfc42installer 
In pseudo-code, here's how the Mfc42.dll download is controlled by this .inf file:

   Search for mfc42.dll in the system (first looking at the same directory
   as the previous version of the control being installed; if not found,
   the file is searched for via the standard search path for DLLs)
   If mfc42.dll is not found,
      install mfc42.dll
   Else
    Compare the file version of the DLL with the FileVersion keyword
    specified in the .inf file 
What is confusing for both the <OBJECT> tag and the .inf file is what to specify for the file version. Unfortunately, the file version reported by the Windows shell (from Windows explorer, right-click on the file, select Properties and click the Version tab) is not always the same as that required for the <OBJECT> tag or an .inf file. For example, these are the reported file versions and correct versions to use for several VC 5.0 DLLs:

   Mfc42.dll:     reported - 4.21.7022  use - 4,21,0,7022
   Msvcrt.dll:    reported - 5.00.7022  use - 5,0,0,7022
   Olepro32.dll:  reported - 5.0.4055   use - 5,0,4055,1 
If you have access to Microsoft Developer Studio, you can open the resources for a file and obtain the correct version in this manner:
  1. From the Developer Studio File menu, select Open, click Open as, and click Resources.


  2. Open the version resource and you will find a FILEVERSION key. This is the proper version to use in the <OBJECT> tag or in the .inf file.


  3. Notice that there is another "FileVersion" key following the Block Header portion of the version resource. This is the version displayed by the Windows shell, and may be different in some cases from the FILEVERSION value in #2 above.


If you do not have access to Microsoft Developer Studio or an environment capable of opening file resources, you can use GetVers.exe to obtain the necessary version. To use the program, simply download it and type:
GetVers <filename>
The following files are available for download from the Microsoft Download Center. Click the file names below to download the files:
Getvers.exe
For more information about how to download files from the Microsoft Download Center, please visit the Download Center at the following Web address
http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center. This is the source code for the GetVer program:

   void reportError()
   {
       LPVOID lpMsgBuf;

       FormatMessage(
           FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
           NULL,
           GetLastError(),
           MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
           (LPTSTR) &lpMsgBuf,
           0,
           NULL );

       cout << (char*)lpMsgBuf << "\n";

       // Free the buffer.
       LocalFree( lpMsgBuf );
   }

   void main( int argc, char *argv[ ], char *envp[ ] )
   {
       cout << "\n";

       if(2 != argc)
       {
           cout << "Syntax: GetVer <File Name>\n";
           return;
       }

       DWORD dwArg;
       DWORD dwInfoSize = GetFileVersionInfoSize(argv[1], &dwArg;);

       if(0 == dwInfoSize)
       {
           cout << "No version info available\n";
           reportError();
           return;
       }

       BYTE* lpBuff = new BYTE[dwInfoSize];

       if(!lpBuff)
       {
           cout << "Out of Memory\n";
           return;
       }

       if(0 == GetFileVersionInfo(argv[1], 0, dwInfoSize, lpBuff))
       {
           cout << "Error retrieving version info\n";
           reportError();
           return;
       }

       VS_FIXEDFILEINFO *vInfo;

       UINT uInfoSize;

       if(0 == VerQueryValue(lpBuff, TEXT("\\"),
               (LPVOID*)&vInfo,
               &uInfoSize))
       {
           cout << "Version information not available\n";
           delete lpBuff;
           return;
       }

       if(0 == uInfoSize)
       {
           cout << "Version information not available\n";
           delete lpBuff;
           return;
       }

       cout << argv[1]
           << " Version: "
           << HIWORD(vInfo->dwFileVersionMS) << ","
           << LOWORD(vInfo->dwFileVersionMS) << ","
           << HIWORD(vInfo->dwFileVersionLS) << ","
           << LOWORD(vInfo->dwFileVersionLS) << "\n";

       delete lpBuff;
   } 

Additional query words:

Keywords : kbfile kbActiveX kbIE300 kbIE301 kbIE400 kbIE302 kbDSupport InetSDKCAB AXSDKCompDownload kbIEFAQ
Version : WINDOWS:3.0,3.01,3.02,4.0
Platform : WINDOWS
Issue type : kbinfo


Last Reviewed: January 27, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.