Microsoft KB Archive/167597

From BetaArchive Wiki
Knowledge Base


SAMPLE: GetVers.exe Specifies Component FileVersion and #Version

Article ID: 167597

Article Last Modified on 5/11/2006



APPLIES TO

  • Microsoft Internet Explorer 3.02
  • Microsoft Internet Explorer 4.0 128-Bit Edition
  • Microsoft Internet Explorer 4.01 Service Pack 2
  • Microsoft Internet Explorer 5.0
  • Microsoft Internet Explorer 5.01
  • Microsoft Internet Explorer 5.5



This article was previously published under Q167597

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; if is not specified correctly, it could cause the component to download incorrectly. If you do not have access to Microsoft Developer Studio or an environment that is capable of opening file resources, you can use the file GetVers.exe to obtain the necessary version.

MORE INFORMATION

For the <OBJECT> tag, use the CODEBASE attribute to specify the file version as follows:

   <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">
   ...</OBJECT>
                

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 through 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 that are installed through 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 Microsoft Visual C++ 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 the file, click Properties, and then 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 Visual C++ 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 as follows:

  1. In Developer Studio, on the File menu, click Open, click Open as, and then click Resources.
  2. Open the version resource, and you 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 that the Windows shell displays and may be different in some cases from the FILEVERSION value in the preceding step.

If you do not have access to Microsoft Developer Studio or an environment that can open file resources, you can use GetVers.exe to obtain the necessary version. To use the program, simply download it and type GetVers <filename> at a command prompt. The following file is available for download from the Microsoft Download Center:

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services


Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file. 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;
   }
                

REFERENCES

For additional information on the CODEBASE attribute, see the following article on the Microsoft Developer Network (MSDN):

For additional information on how #Version works, see the "Managing Versions of a Component" article on MSDN:

For more information on how Internet component download works, see the following archived Microsoft Web Cast:

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:


Additional query words: Getvers

Keywords: kbdownload kbfaq kbfile kbinfo kbsample KB167597