Relayer
Relayer

Reputation: 11

Why does call to Win32::Exe's get_version_info("MyExe.exe") return the wrong FileVersion information?

I'm migrating a bit of Perl script from an ActiveState Perl version to Strawberry Perl. I am having trouble migrating a piece of code that retrieves the file versioning information (contained as metadata) from an executable program.

The following Strawberry Perl code retrieves product version information on the executable file. Why doesn't the Product Version retrieved match the product version as shown when I right-click Properties | Details from Windows explorer (Product Version via right-click is: 25.4.0.0428.001).

enter image description here

Powershell returns the expected value (i.e. ProductVersion is extended information in VersionInfo).

((Get-ItemProperty "e:\\BfsCfgSvc.exe").VersionInfo.ProductVersion)

OUTPUT:

25.12.0.0817.102

How can I retrieve the correct product version using Strawberry Perl?

use Data::Dumper qw( Dumper );
use Win32::Exe   qw( );

my $exe = Win32::Exe->new('e:\\BFSCfgSvc.exe');
my $version_info = $exe->get_version_info();

{
local $Data::Dumper::Useqq  = 1;
local $Data::Dumper::Indent = 1;
print(Dumper($version_info));
}

OUTPUT:

$VAR1 = {
"CompanyName" => "xxxxxxx, Inc.",
"InternalName" => "BFSCfgSvc",
"ProductVersion" => "25.0.0.0",          #<-------------------------------------
"FileDescription" => "xxxxxx ",
"OriginalFilename" => "BFSCfgSvc.CONEXE",
"FileVersion" => "25.0.0.0",
"ProductName" => "xxxxxxxxx ",
"LegalTrademarks" => "xxxxxxxx",
"LegalCopyright" => "xxxxxxx"
};

ActiveState Perl has a Win32::File::Versioninfo module that allows access to the correct version information as shown in the following code snippet:

$DEBUG = 1;
use Win32::File::VersionInfo;


   my $FileVersionInfo = GetFileVersionInfo ("e:\\BFSCfgSvc.exe");
   if ( $FileVersionInfo ) {
      my $lang = ( ( keys %{$FileVersionInfo->{Lang}} )[0] );
      if ($lang) {
         $FileVersion = $FileVersionInfo->{Lang}{$lang}{ProductVersion};
         print "FileVersion: $FileVersion", "\n" if $DEBUG;
      }
   }

OUTPUT:

FileVersion: 25.4.0.0428.001

Upvotes: 1

Views: 79

Answers (1)

brian d foy
brian d foy

Reputation: 132812

Win32::File::VersionInfo is a CPAN module. ActiveState's Perl happens to include more modules beyond the standard library, but that doesn't mean that you are limited to ActiveState to use them.

You should be able to install the module:

$ cpan Win32::File::VersionInfo

After that, your program works just fine for me when I test executables that I have.

Upvotes: 2

Related Questions