I don't use Win32::AdminMisc to get file version information.
I use a combination of Win32::File and Win32::File::VersionInfo
Like so --
[code]
#!/usr/bin/perl
# file-version
# 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);
$finfo = Win32::File::VersionInfo::GetFileVersionInfo("$fname");
$ftime = Win32::FileTime->new("$fname");
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";
[/code]
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
Lloyd, Steve
Sent: Wednesday, November 17, 2004 6:15 PM
To: Greg Foster; [EMAIL PROTECTED]
Subject: RE: Problem with File Versions using Win32-AdminMisc
Roth has contributed tremendously to the Perl community. Remember that
he has to earn a living too.
Now moving away from Perl seems kind of rash; if it can be done, you can
do it in Perl.
How about calling the raw Windows API to get file version as follows.
---------------------------------------------------------------
---------------------------------------------------------------
---------------------------------------------------------------
use Win32::API;
my $file=shift || die "No file";
my $fileversion=&getFileVersion($file);
print "Version of $file is $fileversion\n";
###############
sub getFileVersion {
my $filename = shift @_;
if(!-e $filename){return;}
#GetFileVersionInfoSize
$GetFileVersionInfoSize ||= new Win32::API("Version",
"GetFileVersionInfoSize", [P, P],I) || return $^E;
my $z = 0;
my $sz = $GetFileVersionInfoSize-> Call($filename, $z);
#GetFileVersionInfo
$GetFileVersionInfo ||= new Win32::API("Version",
"GetFileVersionInfo", [P, I, I,P], I) || return $^E;
# Allocate Space For File Version Info
my $FileVer = "\x00" x $sz;
my $ignored = 0;
my $rc = $GetFileVersionInfo-> Call($filename, $ignored, $sz,
$FileVer);
#Parse the results
$FileVer =~ s/[^A-Za-z0-9.:]//go;
# Get only the File Version Info; this xform is "brute-force", but
it works!
$FileVer =~ s/.*FileVersion([\d\.]*).*/$1/go;
return $FileVer;
}
---------------------------------------------------------------
---------------------------------------------------------------
---------------------------------------------------------------
-----Original Message-----
From: [EMAIL PROTECTED] on behalf of
Greg Foster
Sent: Wed 11/17/2004 1:13 PM
To: [EMAIL PROTECTED]
Subject: Re: Problem with File Versions using Win32-AdminMisc
On Fri, 12 Nov 2004 17:46:00 -0500
"Foster, Ken" <[EMAIL PROTECTED]> wrote:
>
>> I have been using Win32-AdminMisc to get file versions for several
>> years. I have a new installation of ActivePerl 5.8.4.810, where I
>>can
>> get the file versions for some files but not others. However, if I
>> run the same script on Perl 5.005 built for MSWin32-x86-object, it
>> returns the file versions for all files.
There have been numerous reports of strange behavior with
Win32-AdminMisc module from Roth under newer versions of Perl. I had
problems enumerating groups under Perl 5.8 and it's corresponding
Admin-Misc module, and when I ran the script under 5.005 it worked
just fine as well.
I'm not sure what the problem is, and it doesn't look like we'll find
out as D. Roth hasn't addressed the questions that are being asked in
regards to this behavior.
My suggestion: Look for another method to do what you're doing. The
solution for my problem was to use vbscript - it wasn't what I wanted
to do, but it works.
>>
>> I tried downloading several versions of AdminMisc from Dave Roth's
>> site (AdminMisc_5008.Zip, AdminMisc_5005.Zip,
>> AdminMisc_5005_AS.Zip), but none return the file versions for
>>certain
>> files (example below).
>>
>> Both Perl versions 5005 & 5.8.4 return the file version for this
>> file:
>>
>> $patch_03_008_file = "\\\\" . $pc .
>> "\\admin\$\\system32\\jdbgmgr.exe";
>> if (Win32::AdminMisc::GetFileInfo( $patch_03_008_file,
>> \%Attribute)){
>> $jdbgmgr_ver = "$Attribute{FileVersion}";
>>
>>
>> Only Perl version 5005 returns the file version for this file
>>(v5.8.4
>> returns nothing):
>>
>> $patch_04_028_file = "\\\\" . $pc .
>> "\\c\$\\PROGRA~1\\Common~1\\Micros~1\\Office10\\mso.dll";
>> if (Win32::AdminMisc::GetFileInfo($patch_04_028_file,
>> \%Attribute)){
>> $mso_dll_ver = "$Attribute{FileVersion}";
>>
>> Can anyone help with this? I really need to be able to run this
>>script
>> on ActivePerl 5.8.4.810, because my new servers are running it.
>> Thanks.
>>
>> -Ken Foster
>>
>>
--------------------------------------------------------
Greg Foster
Technology Services Center
Indiana University of Pennsylvania
Indiana, PA 15705
"There are only 10 types of people in the world, those
who understand binary, and those who don't..."
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
------------------------------------------------------------------------------
Confidentiality notice:
This e-mail message, including any attachments, may contain legally privileged
and/or confidential
information. If you are not the intended recipient(s), or the employee or agent
responsible for delivery
of this message to the intended recipient(s), you are hereby notified that any
dissemination,
distribution, or copying of this e-mail message is strictly prohibited. If you
have received this message
in error, please immediately notify the sender and delete this e-mail message
from your computer.
==============================================================================
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs