Windows: Command line to read version info of an executable file? Windows: Command line to read version info of an executable file? windows windows

Windows: Command line to read version info of an executable file?


wmic datafile where name="C:\\Windows\\System32\\msiexec.exe" get Version /value 

You can use wmic to do it. And you can wrap it into a batch file

@echo off    setlocal enableextensions    set "file=%~1"    if not defined file goto :eof    if not exist "%file%" goto :eof    set "vers="    FOR /F "tokens=2 delims==" %%a in ('        wmic datafile where name^="%file:\=\\%" get Version /value     ') do set "vers=%%a"    echo(%file% = %vers%     endlocal

Save it as (example) getVersion.cmd and call as getVersion.cmd "c:\windows\system32\msiexec.exe"

edited to adapt to comments and not require administrator rights. In this case, an hybrid cmd/javascript file is used to query wmi. Same usage

@if (@this==@isBatch) @then@echo off    setlocal enableextensions    set "file=%~f1"    if not exist "%file%" goto :eof    cscript //nologo //e:jscript "%~f0" /file:"%file%"    endlocal    exit /b@end    var file = WScript.Arguments.Named.Item('file').replace(/\\/g,'\\\\');    var wmi = GetObject('winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2')    var files = new Enumerator(wmi.ExecQuery('Select Version from CIM_datafile where name=\''+file+'\''))     while (!files.atEnd()){        WScript.StdOut.WriteLine(files.item().Version);        files.moveNext();    };    WScript.Quit(0)


If you are willing and able to use PowerShell, the following code will work. If you are on a supported Windows system, PowerShell will be available.

(Get-Item -Path 'C:\Program Files\Java\jdk1.8.0_144\bin\java.exe').VersionInfo |    Format-List -Force

If you must run it in a cmd.exe shell, you could use:

powershell -NoLogo -NoProfile -Command ^    "(Get-Item -Path 'C:\Program Files (x86)\Java\jre1.8.0_201\bin\java.exe').VersionInfo |" ^        "Format-List -Force"


set EXE='c:\firefox\firefox.exe'powershell "(Get-Item -path %EXE%).VersionInfo.ProductVersion"