'Extract File's "Product Version" field using cmd
I am new at batch scripting and looking for a way to extract the "Product Version" field of an .exe file using a command on cmd.
I did managed to get the regular "Version" field of a file using this command:
wmic datafile where Name="C:\\Users\\MyProgram.exe" get Version
is there any way to modify this command line for extracting the "Product Version" field?
Any other solution without wmic at all will also be good :) thanks.
Solution 1:[1]
You can give a try with this batch file to get easily your Product Version; in this example i tried with Google chrome :
@echo off
Title Get Product Version Using WMIC and Batch
Set FullPath=C:\Program Files\Google\Chrome\Application\chrome.exe
Call :Get_AppName "%FullPath%" AppName
Call :GetVersion "%FullPath%" Version
If defined Version (
echo "%FullPath%" ==^> v%Version%
echo "%AppName%" ==^> %Version%
)
Pause
EXIT /B
::----------------------------------------------------------------------------------------
:GetVersion <FullPathApp> <Version>
Rem The argument %~1 represent the full path of the application without the double quotes
Rem The argument %2 represent the variable to be set (in our case %2=Version)
Set "FullPathApp=%~1"
Set "FullPathApp=%FullPathApp:\=\\%"
FOR /F "tokens=2 delims==" %%I IN (
'wmic datafile where "name='%FullPathApp%'" get version /Value 2^>^nul'
) DO FOR /F "delims=" %%A IN ("%%I") DO SET "%2=%%A"
Exit /b
::----------------------------------------------------------------------------------------
:Get_AppName <FullPath> <AppName>
Rem %1 = FullPath
Rem %2 = AppName
for %%i in (%1) do set "%2=%%~nxi"
exit /b
::---------------------------------------------------------------------------------------
Or You can try with Powershell and Batch inspired from Get File Version in PowerShell :
@echo off
Title Get Product Version using Powershell and Batch
Set FullPath=C:\Program Files\Google\Chrome\Application\chrome.exe
echo %FullPath%
Powershell -C "(Get-Item '%FullPath%').VersionInfo.FileVersion"
Pause
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |