Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Does Windows have an executable that I can run in the command shell which returns the version number of an executable (.exe) file?

I see a lot of questions that show how to do it from different languages, and references to third party software to write it, but I can't find a simple shell command to do it. Additional points if I don't need to install anything.

It must be run as normal user. Not administrator.

like image 345
neves Avatar asked Sep 03 '14 15:09

neves


People also ask

How do I check the version of an EXE file?

For example, Oracle Java has the java.exe file, CCleaner has ccleaner.exe and so on. Right click on it and then select Properties. In the Properties window, go to the Details tab. There you will find information about the product name, the product version and so on.

How do I find the version of a file?

One more : To try to force Explore to display "File version", right-click its column-headers, choose "More..." and check "File version" . Result: Version is not displayed for an . ax unless it is renamed to . dll or .exe.

How do I check the version of a file in Windows 10?

Start it up. Under the tools menu, select >> load hive. It then shows all your drives, select the windows folder of the drive in question. It instantly provides the version and keys.


2 Answers

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)
like image 130
MC ND Avatar answered Oct 17 '22 21:10

MC ND


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"
like image 23
lit Avatar answered Oct 17 '22 19:10

lit