使用 cmd 提取文件的"Product Version"字段



我是批处理脚本的新手,正在寻找一种提取"产品版本"的方法。

.exe文件中使用cmd命令的字段。我确实设法得到了常规的"版本";

wmic datafile where Name="C:\Users\MyProgram.exe" get Version

是否有办法修改这个命令行来提取"产品版本"?场吗?

任何其他没有wmic的解决方案也会很好:)谢谢。

您可以尝试使用此批处理文件轻松获得您的产品版本;在这个例子中,我尝试使用Google chrome:

@echo off
Title Get Product Version Using WMIC and Batch
Set FullPath=C:Program FilesGoogleChromeApplicationchrome.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
::---------------------------------------------------------------------------------------

或者您可以尝试使用Powershell和Batch,灵感来自Powershell中的Get File Version:

@echo off
Title Get Product Version using Powershell and Batch
Set FullPath=C:Program FilesGoogleChromeApplicationchrome.exe
echo %FullPath%
Powershell -C "(Get-Item '%FullPath%').VersionInfo.FileVersion"
Pause

最新更新