views:

5133

answers:

5

I need a command line tool to dump standard Windows DLL version info so I can process it by means of a bash script (Cygwin).

As a Java developer I am not very used to Microsoft development tools (though I have a little bit of experience with Microsoft Visual Embedded C++ 4.0 and Microsoft Visual Basic 6.0).

The appropriate tool seems to be mt.exe, as stated on SO. However the only chance I have found to get this little application is to download a 1.29 GB ISO of the Windows SDK for Windows Server 2008 and .NET Framework. I can not believe this is the only way to do it.

I have also found a little application on the Internet called PEView, but it displays too much (and useless in my case) information and it is not a command line application.

Standard objdump bundled inside Cygwin can also dump some information about the DLL files, but I can not see the option to dump DLL version. Note that MajorImageVersion, MinorImageVersion and other fields dumped by this tool (with -p option) are not related to own DLL version.

Any alternatives about what to do? Maybe I missed some important objdump option? Is mt.exe my only choice? If this is the case, is it possible to get it separately from Windows SDK?

+3  A: 

You can also look at filever.exe, which can be downloaded as part of the Windows XP SP2 Support Tools package - only 4.7MB of download.

Franci Penov
which lists only the fileversion, not the other version aspects. Often you need the product version too. `sigcheck` (as uvts_cvs mentions) shows those too, and is a much smaller download.
Jeroen Pluimers
+7  A: 

You can write a VBScript script to get the file version info:

VersionInfo.vbs

set args = WScript.Arguments
Set fso = CreateObject("Scripting.FileSystemObject")
WScript.Echo fso.GetFileVersion(args(0))
Wscript.Quit

You can call this from the command line like this:

cscript //nologo VersionInfo.vbs C:\Path\To\MyFile.dll
Patrick Cuff
Seems viable by means of a command line script. Thanks
Fernando Miguélez
+4  A: 

or you can build one yourself. Open VS, create a new console application. Create a simple project with no ATL or MFC support, leave the stdafx option checked but do not check 'empty project' and call it VersionInfo.

You'll get a simple project with 2 files: VersionInfo.cpp and VersionInfo.h

Open the cpp file and paste the following into it, then compile. You'll be able to run it, first argument is the full filename, it'll print out "Product: 5.6.7.8 File: 1.2.3.4" based on the Version resource block. If there's no version resource it'll return -1, otherwise 0.

Compiles to an 8k binary using the dll CRT, 60k with everything linked statically (set in the C++ options, change "Code Generation page, Runtime options" to "/MT")

HTH.

PS. If you don't want to use Visual Studio, it'll still compile using any c++ compiler (fingers crossed), but you'll almost certainly have to change the #pragma - just specify that lib in the linker settings instead, the pragma's just a shorthand to automatically link with that library.


// VersionInfo.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>

#pragma comment(lib, "version.lib")

int _tmain(int argc, _TCHAR* argv[])
{
    DWORD handle = 0;
    DWORD size = GetFileVersionInfoSize(argv[1], &handle);
    BYTE* versionInfo = new BYTE[size];
    if (!GetFileVersionInfo(argv[1], handle, size, versionInfo))
    {
     delete[] versionInfo;
     return -1;
    }
    // we have version information
    UINT len = 0;
    VS_FIXEDFILEINFO*   vsfi = NULL;
    VerQueryValue(versionInfo, L"\\", (void**)&vsfi, &len);

    WORD fVersion[4], pVersion[4];
    fVersion[0] = HIWORD(vsfi->dwFileVersionMS);
    fVersion[1] = LOWORD(vsfi->dwFileVersionMS);
    fVersion[2] = HIWORD(vsfi->dwFileVersionLS);
    fVersion[3] = LOWORD(vsfi->dwFileVersionLS);
    pVersion[0] = HIWORD(vsfi->dwProductVersionMS);
    pVersion[1] = LOWORD(vsfi->dwProductVersionMS);
    pVersion[2] = HIWORD(vsfi->dwProductVersionLS);
    pVersion[3] = LOWORD(vsfi->dwProductVersionLS);

    printf("Product: %d.%d.%d.%d File: %d.%d.%d.%d\n", 
        pVersion[0], pVersion[1], 
        pVersion[2], pVersion[3], 
        fVersion[0], fVersion[1], 
        fVersion[2], fVersion[3]);
    delete[] versionInfo;

    return 0;
}
gbjbaanb
Not exactly what I was looking for, but still interesting to develop an small program to do it. Thanks.
Fernando Miguélez
no? What version info did you want? AFAIK Windows only has version info stored in the resource blocks - these are what you see when you open properties in explorer.
gbjbaanb
+5  A: 

Use Microsoft Sysinternals Sigcheck http://technet.microsoft.com/en-us/sysinternals/bb897441.aspx. It is only 114 KB.

uvts_cvs
A: 

Way to teach a man to build a fishing rod :-).

SamB