I have two executables (file1.exe and file2.exe).

Both are the "same" file, but one is a newer version from the vendor than the other. When I open up the properties for one of them, I get the following under the Details tab:

enter image description here

In batch, I'd like to compare the two file versions and do something if the versions are different ("if this, then that" type of scenario).

I've searched high and low, but I can't seem to find a method of looking at the "File Version" attribute in batch. Is there any means of accomplishing this?

Please note that this is not intended to be a "write a script for me" question. The intent is for a more general overview or description of the answer, at which point, the details should be able to come much more easily.


Sigcheck - Sysinternals Suite

sigcheck -a -q %windir%\system32\mstsc.exe

- if need add MD5, SHA1, PESHA1, SHA256

    sigcheck -a -q -h %windir%\system32\mstsc.exe

- test version, and run command:

    sigcheck -a -q %windir%\system32\mstsc.exe | find "Prod version:" | find "6.0.6001.18564" && Echo "RDP 6.0.6001.18564"

filever - Support tools:

Windows XP Service Pack 2 Support Tools or

Windows Server 2003 Service Pack 2 32-bit Support Tools

filever /V %windir%\system32\mstsc.exe

var 2:

  • filever /V %windir%\system32\mstsc.exe | findstr "FileDesc Version"
  • filever /V %windir%\system32\mstsc.exe | findstr "ProductVersion" | find "6.0.6001.18564" && Echo "RDP 6.0.6001.18564"
  • filever /V %windir%\system32\mstsc.exe | findstr "ProductVersion" | find "6.0.6001.18564" || Echo "NOT 6.0.6001.18564"


wmic datafile where "name='C:\\<windows dir>\\system32\\mstsc.exe'" get version



powershell (gi %windir%\system32\mstsc.exe).versioninfo.FileDescription


powershell (gi %windir%\system32\mstsc.exe).versioninfo ^|Ft -Au

script version compare:

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


Major  Minor  Build  Revision
-----  -----  -----  --------
6      0      6001   18564
Run version list block


cscript //Nologo vers01.vbs


WScript.Echo CreateObject("Scripting.FileSystemObject").GetFileVersion(CreateObject("WScript.Shell").Environment("Process")("WINDIR") & "\system32\mstsc.exe")


cscript //Nologo vers01.js


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

python, pefile:

pefile modyle install: Unzip, run 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


php vers01.php

php.ini (%windir%):

extension_dir = C:\php\ext\



$path = getenv('SystemRoot').'\\system32\\mstsc.exe';
$fso = new COM("Scripting.FileSystemObject");
echo $fso->GetFileVersion($path);


Install Win32::File::VersionInfo module: cpan Win32::File::VersionInfo

use Win32::File::VersionInfo;

  $fn=$ENV{windir} . "\\system32\\mstsc.exe";
  if($fl){print $fl->{FileVersion},"\n";}
  • 1
    Try and keep the edits substantive and ease up on bumping every 10 minutes – random Mar 20 '15 at 12:31
  • 4
    @random Alas. It attempts to improve what is. Thank you for your comment, I'll try to make big changes. – STTR Mar 20 '15 at 12:37

@STTR' answer is fine, except it does not provide a way to namely compare versions in batch, as this may be also the problem, for example, when comparing 10.0.10049 with 6.3.9600.

If you'll do it with plain IF %ver1% GTR %ver%, you'll get string comparison, and 6.3.9600 will appear bigger than 10.0.10049.

I know you've told it's not "write for me", but this is case when it's easier to write code than explain in plain English (and the code is self-explanatory).

From https://superuser.com/a/363308/131936 I've found how to read file version using wmic, which is shipped with bare windows.


ECHO Usage: %0 <file> [<MinVer>]
ECHO If second argument provided, returns error level 1 if version of file is less than required
ECHO Otherwise, sets %%filever%% variable to file version No.

rem https://superuser.com/a/363308/131936
SET "fileNameForWMIC=%~1"
SET fileNameForWMIC=%fileNameForWMIC:\=\\%
FOR /F "usebackq skip=1" %%I IN (`wmic datafile where Name^="%fileNameForWMIC%" get Version`) DO (
    SET filever=%%~I
    GOTO :break
IF "%~2"=="" (
    SET "filever=%filever%"
    EXIT /B
FOR /F "delims=. tokens=1,2,3,4" %%I IN ("%filever%") DO (
    SET fileverSub1=%%I
    SET fileverSub2=%%J
    SET fileverSub3=%%K
    SET fileverSub4=%%L
FOR /F "delims=. tokens=1,2,3,4" %%I IN ("%~2") DO (
    SET chkSub1=%%I
    SET chkSub2=%%J
    SET chkSub3=%%K
    SET chkSub4=%%L
IF NOT DEFINED fileverSub2 SET fileverSub2=0
IF NOT DEFINED fileverSub3 SET fileverSub3=0
IF NOT DEFINED fileverSub4 SET fileverSub4=0
IF NOT DEFINED chkSub2 SET chkSub2=0
IF NOT DEFINED chkSub3 SET chkSub3=0
IF NOT DEFINED chkSub4 SET chkSub4=0
IF %chkSub1% GTR %fileverSub1% EXIT /B 1
IF %chkSub2% GTR %fileverSub2% EXIT /B 1
IF %chkSub3% GTR %fileverSub3% EXIT /B 1
IF %chkSub4% GTR %fileverSub4% EXIT /B 1

How to use this regarding you your question:

first, read one file version:

CALL compareVersion.cmd file1.exe
SET file1ver=%filever%

then compare it with other file(s):

CALL compareVersion.cmd file2.exe %file1ver%

    … do this when file2 is lower version than file1…
) ELSE (
    … do this when file2 is higher or equal to version of file1…

also, you can hardcode version, if you want:

CALL compareVersion.cmd file2.exe || (ECHO Min required version not provided & EXIT /B)

P.S. Here is my script to read/check windows version, built on similar principle.


Not exactly for version checking, but you can calculate and compare the MD5 or SHA1 checksum of two files and then compare if they're the same. If the checksum strings are equal, the two files are exactly same (hence the same version), else different.

You can use the FCIV tool in command line to calculate checksum.

  • 1
    I don't believe that's what the OP is after... I think they are after the file version, as reported by Windows – Canadian Luke Mar 20 '15 at 15:50

There is no simple way to compare version numbers with multiple decimals using Windows commands (batch). PowerShell does have a way to do this using [System.Version].

set ver1=
set ver2=
PowerShell $a=[System.Version]"$env:ver1" -gt [System.Version]"$env:ver2"; ^
if ($a) {Set-Variable -Name "a" -Value "1"}; ^
exit $a

if %errorlevel% == 0 echo ver1 is greater than ver2
if %errorlevel% == 1 echo ver1 is less than than ver2

How this works:

  • Using Windows commands, set two variables, ver1 and ver2
  • Start Powershell and use ; ^ to end multiple lines
  • Call [System.Version] to compare the versions
  • The variables we defined are passed to PowerShell as $env: variables
  • If ver1 is greater than 'ver2' then $a will be set to True
  • If $a is True, then set it to 1
  • Exit and set $a as the errorlevel
  • Test the errorlevel for 0 or 1

For more PowerShell comparison operators, see https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comparison_operators?view=powershell-7.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy