Re: looking for shell program to retrieve property info from windows files
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 /* * 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 [EMAIL PROTECTED] * * $Id: version.cc,v 1.6 2005/01/19 14:49:52 jt Exp $ */ #include windows.h #include stdio.h #ifdef __CYGWIN__ #include sys/cygwin.h #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 0x, aFixedFileInfo-dwProductVersionLS 16, aFixedFileInfo-dwProductVersionLS 0x); printf(FileVersion = %d.%d.%d.%d\n, aFixedFileInfo-dwFileVersionMS
Re: looking for shell program to retrieve property info from windows files
I did something similar in perl. #!/usr/bin/perl # Version 1.0 # - It does what it does. use Digest::MD5 qw(md5_hex); use Win32::File; use Win32::File::VersionInfo; use Win32::FileTime; $fname = $ARGV[0]; print \nFile: $fname; if (! -e $fname) { print \n\nI cannot find your file.; print \nError!; print \nperl: $!\nos: $^E\n; die; } Win32::File::GetAttributes($fname,$fattr); #print \nWin32::File::GetAttrubutes(\$fname\,\$fattr) - $fattr; $finfo = Win32::File::VersionInfo::GetFileVersionInfo($fname); #print \n\$finfo = Win32::File::VersionInfo::GetFileVersionInfo(\$fname\) - $finfo; $ftime = Win32::FileTime-new($fname); #print \n\$ftime = Win32::FileTime-new(\$fname\) - $ftime; if ($finfo) { print \nFile Version: , $finfo-{FileVersion}; print \nProduct Version: , $finfo-{ProductVersion}; %Flags = $finfo-{Flags}; foreach $key (keys %Flags) { if ($Flags{$key}) { print \nFlags: , $key; } # end of if the value exists } # end of foreach flag print \nOS: , $finfo-{OS}; print \nType: , $finfo-{Type}; print \nDate: , $finfo-{Date}; my $lang = (keys %{$finfo-{Lang}})[0]; if ($lang) { print \nLanguage: , $lang; print \nComments: , $finfo-{Lang}{$lang}{Comments}; print \nCompanyName: , $finfo-{Lang}{$lang}{CompanyName}; print \nFileDescription: , $finfo-{Lang}{$lang}{FileDescription}; print \nFileVersion: , $finfo-{Lang}{$lang}{FileVersion}; print \nInternalName: , $finfo-{Lang}{$lang}{InternalName}; print \nCopyright: , $finfo-{Lang}{$lang}{Copyright}; print \nTrademarks: , $finfo-{Lang}{$lang}{Trademarks}; print \nOriginalFilename: , $finfo-{Lang}{$lang}{OriginalFilename}; print \nProductName: , $finfo-{Lang}{$lang}{ProductName}; print \nProductVersion: , $finfo-{Lang}{$lang}{ProductVersion}; print \nPrivateBuild: , $finfo-{Lang}{$lang}{PrivateBuild}; print \nSpecialBuild: , $finfo-{Lang}{$lang}{SpecialBuild}; } } # end of if else { print \n\nI cannot get the file flags.; print \nError!; print \nAre you sure this is a valid Microsoft Portable Executable (PE) file with valid version information?\n; } if ($fattr) { $#attr = -1; if ($fattr ARCHIVE) { push(@attr,archive); } if ($fattr COMPRESSED) { push(@attr,compressed); } if ($fattr DIRECTORY) { push(@attr,directory); } if ($fattr HIDDEN) { push(@attr,hidden); } if ($fattr NORMAL) { push(@attr,normal); } if ($fattr OFFLINE) { push(@attr,offline); } if ($fattr READONLY) { push(@attr,readonly); } if ($fattr SYSTEM) { push(@attr,system); } if ($fattr TEMPORARY) { push(@attr,temporary); } print \nFile Attributes: , join(, ,@attr); } else { print \n\nI cannot get the file attributes.; print \nError!; print \nperl: $!\nos: $^E\n; } if ($ftime) { printf( \nCreated : %4d/%02d/%02d %02d:%02d:%02d, $ftime-Create( 'year', 'month', 'day', 'hour', 'minute', 'second' ) ); printf( \nAccessed : %4d/%02d/%02d %02d:%02d:%02d, $ftime-Access( 'year', 'month', 'day', 'hour', 'minute', 'second' ) ); printf( \nModified : %4d/%02d/%02d %02d:%02d:%02d, $ftime-Modify( 'year', 'month', 'day', 'hour', 'minute', 'second' ) ); } # end of if else { print \n\nI cannot get the file times.; print \nError!; print \nperl: $!\nos: $^E\n; } print \nMD5 Checksum: , md5_hex($fname); print \n; On Wed, 19 Jan 2005 08:03:00 -0500, Jason Tishler [REMOVED] wrote: 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:
Re: looking for shell program to retrieve property info from windows files
On Wed, 19 Jan 2005, Jason Tishler wrote: 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. Jason, This looks useful. Feel like proposing this for cygutils? Igor -- http://cs.nyu.edu/~pechtcha/ |\ _,,,---,,_[EMAIL PROTECTED] ZZZzz /,`.-'`'-. ;-;;,_[EMAIL PROTECTED] |,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski, Ph.D. '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow! The Sun will pass between the Earth and the Moon tonight for a total Lunar eclipse... -- WCBS Radio Newsbrief, Oct 27 2004, 12:01 pm EDT -- 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/
looking for shell program to retrieve property info from windows files
does anyone know of a shell program to retrieve the property info from windows files. I need info like the fileversion or prodversion. -- 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/