如何从命令行比较两个可执行文件的版本?

13 batch file-attributes

我有两个可执行文件(file1.exe 和 file2.exe)。

两者都是“相同”的文件,但其中一个是供应商提供的比另一个更新的版本。当我打开其中之一的属性时,我会在“详细信息”选项卡下看到以下内容:

在此处输入图片说明

在批处理中,我想比较两个文件版本并在版本不同时做一些事情(“如果这个,那么那个”类型的场景)。

我搜索了高低,但似乎找不到批量查看“文件版本”属性的方法。有没有办法做到这一点?

请注意,这不是“为我编写脚本”的问题。目的是对答案进行更一般的概述或描述,在这一点上,细节应该能够更容易地出现。

STT*_*TTR 27

Sigcheck - Sysinternals 套件

sigcheck -a -q %windir%\system32\mstsc.exe
Run Code Online (Sandbox Code Playgroud)

- 如果需要添加 MD5、SHA1、PESHA1、SHA256

    sigcheck -a -q -h %windir%\system32\mstsc.exe
Run Code Online (Sandbox Code Playgroud)

- 测试版本,并运行命令:

    sigcheck -a -q %windir%\system32\mstsc.exe | find "Prod version:" | find "6.0.6001.18564" && Echo "RDP 6.0.6001.18564"
Run Code Online (Sandbox Code Playgroud)

filever - 支持工具:

Windows XP Service Pack 2 支持工具

Windows Server 2003 Service Pack 2 32 位支持工具

filever /V %windir%\system32\mstsc.exe
Run Code Online (Sandbox Code Playgroud)

变量 2:

微信:

wmic datafile where "name='C:\\<windows dir>\\system32\\mstsc.exe'" get version
Run Code Online (Sandbox Code Playgroud)

电源外壳:

文件描述:

powershell (gi %windir%\system32\mstsc.exe).versioninfo.FileDescription
Run Code Online (Sandbox Code Playgroud)

版本:

powershell (gi %windir%\system32\mstsc.exe).versioninfo ^|Ft -Au
Run Code Online (Sandbox Code Playgroud)

脚本版本比较:

$VerArr = [version]"8.2.6001.18564", [version]"6.0.6001.18564"
[version]$v1="8.2.6001.18564"
[version]$v2="6.0.6001.18564"
[version]$v3=(gi $env:windir\system32\mstsc.exe).versioninfo.ProductVersion
$v3
$v3 -ge $v1
$v3 -ge $v2
If ($VerArr -contains $v3)
   {
   echo 'Run version list block'
   }
Run Code Online (Sandbox Code Playgroud)

输出:

Major  Minor  Build  Revision
-----  -----  -----  --------
6      0      6001   18564
False
True
Run version list block
Run Code Online (Sandbox Code Playgroud)

WSH:

cscript //Nologo vers01.vbs
Run Code Online (Sandbox Code Playgroud)

vers01.vbs:

WScript.Echo CreateObject("Scripting.FileSystemObject").GetFileVersion(CreateObject("WScript.Shell").Environment("Process")("WINDIR") & "\system32\mstsc.exe")
Run Code Online (Sandbox Code Playgroud)

脚本:

cscript //Nologo vers01.js
Run Code Online (Sandbox Code Playgroud)

vers01.js:

WScript.Echo(new ActiveXObject("Scripting.FileSystemObject").GetFileVersion(new ActiveXObject("WScript.Shell").ExpandEnvironmentStrings("%windir%")+"//system32//mstsc.exe"));
Run Code Online (Sandbox Code Playgroud)

蟒蛇,pefile

pefile modyle install: 解压,运行 python setup.py install

import pefile, os

pe = pefile.PE(os.path.join(os.environ['WINDIR'],'system32\mstsc.exe'))
ProductVersion = pe.FileInfo[0].StringTable[0].entries['ProductVersion']
print ProductVersion
Run Code Online (Sandbox Code Playgroud)

PHP:

php vers01.php
Run Code Online (Sandbox Code Playgroud)

php.ini ( %windir%):

extension_dir = C:\php\ext\

[COM_DOT_NET]
extension=php_com_dotnet.dll
Run Code Online (Sandbox Code Playgroud)

vers01.php:

<?php
$path = getenv('SystemRoot').'\\system32\\mstsc.exe';
$fso = new COM("Scripting.FileSystemObject");
echo $fso->GetFileVersion($path);
?>
Run Code Online (Sandbox Code Playgroud)

珀尔:

安装 Win32::File::VersionInfo 模块: cpan Win32::File::VersionInfo

use Win32::File::VersionInfo;

  $fn=$ENV{windir} . "\\system32\\mstsc.exe";
  $fl=GetFileVersionInfo($fn);
  if($fl){print $fl->{FileVersion},"\n";}
Run Code Online (Sandbox Code Playgroud)

  • @random 唉。它试图改善现状。谢谢你的评论,我会努力做出大的改变。 (4认同)