Get file version from Windows command line for use in a variable?

From my understanding you need filever.exe to do this. As pointed out in the comments. Also, I ripped the below word for word from here

How to use the Filever.exe tool to obtain specific information about a file in Windows

From what I gather about filever's output it's always in columns and you want the fifth column (version). So a simple for should suffice:

for /f "tokens=5 delims= " %%v in ('filever myFile.dll /b') do echo %%v

You can check using sigcheck.exe which is part of Sysinternals Suite, e.g.

$ sigcheck.exe -q -n app.exe
5.0.0.1241

By specifying -q (quiet, no banner) and -n will show you only the file version number, so you can assign it into the variable.


If you're using Sigcheck64, the 64bit version provided for Nano Server, which doesn't support 32bit programs, the -q parameter has been replaced by -nobanner. E.g.

$ sigcheck.exe -nobanner -n app.exe
    5.0.0.1241

Source: What is the difference between Sigcheck and Sigcheck64? and SigCheck manual page.