From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17385 invoked by alias); 19 Jan 2005 13:03:14 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 17337 invoked from network); 19 Jan 2005 13:03:01 -0000 Received: from unknown (HELO rwcrmhc11.comcast.net) (204.127.198.35) by sourceware.org with SMTP; 19 Jan 2005 13:03:01 -0000 Received: from stella (pcp0010433018pcs.eatntn01.nj.comcast.net[68.39.139.106]) by comcast.net (rwcrmhc11) with ESMTP id <200501191303000130098bvne>; Wed, 19 Jan 2005 13:03:00 +0000 Received: from [127.0.0.1] (helo=stella.tishler.net) by stella with smtp (Exim 4.43) id IAKEX1-00034G-2S for cygwin@cygwin.com; Wed, 19 Jan 2005 08:03:01 -0500 Received: by stella.tishler.net (sSMTP sendmail emulation); Wed, 19 Jan 2005 08:03:01 -0500 Date: Wed, 19 Jan 2005 13:41:00 -0000 From: Jason Tishler To: cygwin@cygwin.com Subject: Re: looking for shell program to retrieve property info from windows files Message-ID: <20050119130300.GA3452@tishler.net> Mail-Followup-To: cygwin@cygwin.com References: <200501181915090630.3FC77633@smtp.atl.yahoo.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="cNdxnHkX5QqsyA0e" Content-Disposition: inline In-Reply-To: <200501181915090630.3FC77633@smtp.atl.yahoo.com> User-Agent: Mutt/1.4.1i X-IsSubscribed: yes X-SW-Source: 2005-01/txt/msg00884.txt.bz2 --cNdxnHkX5QqsyA0e Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 944 Jaye, On Tue, Jan 18, 2005 at 07:15:09PM -0500, Jaye Speaks wrote: > does anyone know of a shell program to retrieve the property info from > windows files. I need info like the fileversion or prodversion. No, so I wrote my own: $ version 'C:\Program Files\Microsoft Office\OFFICE11\WINPROJ.EXE' Required Information: ProductVersion = 11.0.2003.816 FileVersion = 11.0.2003.816 Optional Information: $ cygversion /mnt/c/Program\ Files/Microsoft\ Office/OFFICE11/WINPROJ.EXE Required Information: ProductVersion = 11.0.2003.816 FileVersion = 11.0.2003.816 Optional Information: See attached for the source and Makefile. Note the Makefile builds two executables: version.exe: Mingw executable cygversion.exe: Cygwin executable Jason -- PGP/GPG Key: http://www.tishler.net/jason/pubkey.asc or key servers Fingerprint: 7A73 1405 7F2B E669 C19D 8784 1AFD E4CC ECF4 8EF6 --cNdxnHkX5QqsyA0e Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="version.cc" Content-length: 4267 /* * Copyright (c) 2005 Jason Tishler * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * A copy of the GNU General Public License can be found at * http://www.gnu.org/ * * Written by Jason Tishler * * $Id: version.cc,v 1.6 2005/01/19 14:49:52 jt Exp $ */ #include #include #ifdef __CYGWIN__ #include #endif const char* GetVersionString(const void* aVersionInfo, const char* aVersionName); const VS_FIXEDFILEINFO* GetFixedFileInfo(const void* aVersionInfo); void PrintRequiredVersionInfo(const VS_FIXEDFILEINFO* aFixedFileInfo); void PrintOptionalVersionInfo(char* aVersionInfo); bool GetFullPathName(const char* aFileName, char* aPathName, unsigned int aSize); void PrintUsage(); const char* aVersionNames[] = { "Comments", "CompanyName", "FileDescription", "FileVersion", "InternalName", "LegalCopyright", "LegalTrademarks", "OriginalFilename", "PrivateBuild", "ProductName", "ProductVersion", "SpecialBuild" }; int main(int argc, const char* argv[]) { if (argc < 2) { PrintUsage(); exit(1); } for (int i = 1; i < argc; i++) { char aPathName[MAX_PATH + 1]; const char* aFileName = argv[i]; GetFullPathName(aFileName, aPathName, sizeof(aPathName)); if (argc > 2) { printf("%s%s:\n", (i != 1) ? "\n" : "", aFileName); } DWORD aHandle = 0; DWORD aSize = GetFileVersionInfoSize(aPathName, &aHandle); if (aSize == 0) { exit(2); } char* aVersionInfo = new char[aSize]; BOOL aStatus = GetFileVersionInfo(aPathName, aHandle, aSize, aVersionInfo); if (!aStatus) { delete [] aVersionInfo; exit(3); } const VS_FIXEDFILEINFO* aFixedFileInfo = GetFixedFileInfo(aVersionInfo); PrintRequiredVersionInfo(aFixedFileInfo); PrintOptionalVersionInfo(aVersionInfo); delete [] aVersionInfo; } exit(0); } const char* GetVersionString(const void* aVersionInfo, const char* aVersionName) { const char* aSeparator = "\\"; const char* aPrefix = "StringFileInfo"; const char* aLangCodePage = "040904b0"; char aVersionPath[MAX_PATH + 1]; strcpy(aVersionPath, aSeparator); strcat(aVersionPath, aPrefix); strcat(aVersionPath, aSeparator); strcat(aVersionPath, aLangCodePage); strcat(aVersionPath, aSeparator); strcat(aVersionPath, aVersionName); void* aBuffer = 0; UINT aSize = 0; VerQueryValue((void*) aVersionInfo, aVersionPath, &aBuffer, &aSize); return (const char*) aBuffer; } const VS_FIXEDFILEINFO* GetFixedFileInfo(const void* aVersionInfo) { void* aBuffer = 0; UINT aSize = 0; const char* aRootBlock = "\\"; VerQueryValue((void*) aVersionInfo, (char*) aRootBlock, &aBuffer, &aSize); return (const VS_FIXEDFILEINFO*) aBuffer; } void PrintRequiredVersionInfo(const VS_FIXEDFILEINFO* aFixedFileInfo) { if (!aFixedFileInfo) return; printf("Required Information:\n"); printf(" ProductVersion = %d.%d.%d.%d\n", aFixedFileInfo->dwProductVersionMS >> 16, aFixedFileInfo->dwProductVersionMS & 0xffff, aFixedFileInfo->dwProductVersionLS >> 16, aFixedFileInfo->dwProductVersionLS & 0xffff); printf(" FileVersion = %d.%d.%d.%d\n", aFixedFileInfo->dwFileVersionMS >> 16, aFixedFileInfo->dwFileVersionMS & 0xffff, aFixedFileInfo->dwFileVersionLS >> 16, aFixedFileInfo->dwFileVersionLS & 0xffff); } void PrintOptionalVersionInfo(char* aVersionInfo) { printf("Optional Information:\n"); int aNumVersionNames = sizeof(aVersionNames) / sizeof(const char*); for (int i = 0; i < aNumVersionNames; i++) { const char* aVersionName = aVersionNames[i]; const char* aVersionString = GetVersionString(aVersionInfo, aVersionName); if (aVersionString) printf(" %s: %s\n", aVersionName, aVersionString); } } bool GetFullPathName(const char* aFileName, char* aPathName, unsigned int aSize) { #ifdef __CYGWIN__ cygwin_conv_to_full_win32_path(aFileName, aPathName); return true; #else char *aDummy; DWORD aStatus = GetFullPathName (aFileName, aSize, aPathName, &aDummy); return (aStatus > 0); #endif // __CYGWIN__ } void PrintUsage() { printf("usage: version files...\n"); } --cNdxnHkX5QqsyA0e Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=Makefile Content-length: 716 # # Copyright (c) 2005 Jason Tishler # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # A copy of the GNU General Public License can be found at # http://www.gnu.org/ # # Written by Jason Tishler # # $Id: Makefile,v 1.3 2005/01/19 14:50:10 jt Exp $ # all: version cygversion CC = g++ CFLAGS = -O2 -s Files = version.cc Libs = -lversion version: $(Files) $(CC) $(CFLAGS) -mno-cygwin -o $@ $(Files) $(Libs) cygversion: $(Files) $(CC) $(CFLAGS) -o $@ $(Files) $(Libs) clean: $(RM) *.exe --cNdxnHkX5QqsyA0e Content-Type: text/plain; charset=us-ascii Content-length: 218 -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ --cNdxnHkX5QqsyA0e--