You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Strawberry Perl中Win32::Exe获取版本信息错误的原因及解决方法

解决Strawberry Perl获取EXE正确产品版本的问题

问题背景

将Perl脚本从ActiveState Perl迁移到Strawberry Perl时,使用Win32::Exe模块读取EXE文件的ProductVersion时得到的是25.0.0.0,但Windows资源管理器、PowerShell命令((Get-ItemProperty "e:\BfsCfgSvc.exe").VersionInfo.ProductVersion)以及ActiveState Perl的Win32::File::VersionInfo模块都能获取到正确的版本(如25.4.0.0428.001)。

解决方案

方法1:在Strawberry Perl中安装Win32::File::VersionInfo模块

直接沿用ActiveState Perl中可用的Win32::File::VersionInfo模块,步骤如下:

  1. 打开Strawberry Perl自带的命令行工具(Strawberry Perl (64-bit) Command Prompt)
  2. 执行安装命令:
cpanm Win32::File::VersionInfo
  1. 使用原有的代码即可获取正确版本:
use Win32::File::VersionInfo;

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

方法2:调用PowerShell命令获取版本

如果不想额外安装模块,可直接调用PowerShell命令并捕获输出:

my $exe_path = 'e:\BFSCfgSvc.exe';
my $product_version = `powershell -Command "(Get-ItemProperty '$exe_path').VersionInfo.ProductVersion"`;
chomp $product_version;
print "ProductVersion: $product_version\n";

方法3:排查Win32::Exe的问题(可选)

Win32::Exe返回错误版本可能是因为模块解析版本资源的逻辑问题,比如仅读取了固定的版本字段而非字符串版本。如果坚持使用该模块,可以查看模块源码或提交issue,但前两种方法更直接高效。

内容的提问来源于stack exchange,提问作者Relayer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 15:40:57