Windows: Command line for reading version information of an executable file?

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

I see a lot of questions that show how to do this from different languages, and links to third-party software to write it, but I can not find a simple shell command for this. Additional points if I do not need to install anything.

It should run as a regular user. Not an administrator.

+15
source share
5 answers
wmic datafile where name="C:\\Windows\\System32\\msiexec.exe" get Version /value 

You can use wmic for this. And you can wrap it in 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 getVersion.cmd "c:\windows\system32\msiexec.exe"

edited to adapt to comments and not require administrator rights. In this case, the cmd / javascript hybrid file is used for the wmi request. Same use

 @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) 
+24
source

If you are ready and can use PowerShell ...

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

If you must run it in the cmd.exe shell, you can use:

 powershell -NoLogo -NoProfile -Command ^ (get-item -Path 'C:\Program Files\Java\jdk1.8.0_152\bin\java.exe').VersionInfo ^| ^ Format-List -Force 
+10
source
 set EXE='c:\firefox\firefox.exe' powershell "(Get-Item -path %EXE%).VersionInfo.ProductVersion" 
+6
source

and in one way with makecab :

 ; @echo off ;;goto :end_help ;;setlocal DsiableDelayedExpansion ;;; ;;; ;;; fileinf /l list of full file paths separated with ; ;;; fileinf /f text file with a list of files to be processed ( one on each line ) ;;; fileinf /? prints the help ;;; ;;:end_help ; REM Creating a Newline variable (the two blank lines are required!) ; set NLM=^ ; set NL=^^^%NLM%%NLM%^%NLM%%NLM% ; if "%~1" equ "/?" type "%~f0" | find ";;;" | find /v "find" && exit /b 0 ; if "%~2" equ "" type "%~f0" | find ";;;" | find /v "find" && exit /b 0 ; setlocal enableDelayedExpansion ; if "%~1" equ "/l" ( ; set "_files=%~2" ; echo !_files:;=%NL%!>"%TEMP%\file.paths" ; set _process_file="%TEMP%\file.paths" ; goto :get_info ; ) ; if "%~1" equ "/f" if exist "%~2" ( ; set _process_file="%~2" ; goto :get_info ; ) ; echo incorect parameters & exit /b 1 ; :get_info ; set "file_info=" ; makecab /d InfFileName=%TEMP%\file.inf /d "DiskDirectory1=%TEMP%" /f "%~f0" /f %_process_file% /v0>nul ; for /f "usebackq skip=4 delims=" %%f in ("%TEMP%\file.inf") do ( ; set "file_info=%%f" ; echo !file_info:,=%nl%! ; ) ; endlocal ;endlocal ; del /q /f %TEMP%\file.inf 2>nul ; del /q /f %TEMP%\file.path 2>nul ; exit /b 0 .set DoNotCopyFiles=on .set DestinationDir=; .set RptFileName=nul .set InfFooter=; .set InfHeader=; .Set ChecksumWidth=8 .Set InfDiskLineFormat=; .Set Cabinet=off .Set Compress=off .Set GenerateInf=ON .Set InfDiskHeader=; .Set InfFileHeader=; .set InfCabinetHeader=; .Set InfFileLineFormat=",file:*file*,date:*date*,size:*size*,csum:*csum*,time:*time*,vern:*ver*,vers:*vers*,lang:*lang*" 

Example output (it has a lowercase version, which is a small addition to the wmic method :)):

 c:> fileinfo.bat /l C:\install.exe file:install.exe date:11/07/07 size:562688 csum:380ef239 time:07:03:18a vern:9.0.21022.8 vers:9.0.21022.8 built by: RTM lang:1033 

also you can take a look at tooltipinfo.bat

+3
source

This will give you only the version of the file:

 wmic datafile where name='c:\\windows\\system32\\notepad.exe' get version 

Result:

 Version 6.1.7601.18917 
+3
source

Source: https://habr.com/ru/post/974753/


All Articles