提取文件版本版本“ s&quot”使用CMD的字段

发布于 2025-01-24 16:59:34 字数 243 浏览 2 评论 0原文

我是批处理脚本的新手,正在寻找一种使用CMD上命令提取.exe文件的“产品版本”字段的方法。

我确实使用此命令设法获得了文件的常规“版本”字段:

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

是否有任何方法可以修改此命令行以提取“产品版本”字段?

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

内心旳酸楚 2025-01-31 16:59:34

您可以尝试使用此批处理文件来轻松获取产品版本;在此示例中,我尝试了 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
::---------------------------------------------------------------------------------------

或者您可以尝试使用PowerShell和Batch 在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

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
过期以后 2025-01-31 16:59:34

我假设是“产品版本”字段,它在您要寻找的exe-File的“属性对话框”的详细信息选项卡中显示。

这就是c:\ windows \ system32 \ Notepad.exe

“在此处输入映像说明”

在qwertys上构建对原始问题的评论,您无法获得'产品版本',唯一的“文件版本”(即''版本')使用wmic

使用 notpad.exe 作为示例

,下面显示了如何列出可以查询使用wmic 的所有值,

C:\>wmic datafile where name='c:\\windows\\system32\\notepad.exe' get /value


AccessMask=1179817
Archive=TRUE
Caption=c:\windows\system32\notepad.exe
Compressed=FALSE
CompressionMethod=
CreationClassName=CIM_LogicalFile
CreationDate=20221020203835.352020+000
CSCreationClassName=Win32_ComputerSystem
CSName=PCS-SES-A
Description=c:\windows\system32\notepad.exe
Drive=c:
EightDotThreeFileName=c:\windows\system32\notepad.exe
Encrypted=FALSE
EncryptionMethod=
Extension=exe
FileName=notepad
FileSize=201216
FileType=Application
FSCreationClassName=Win32_FileSystem
FSName=NTFS
Hidden=FALSE
InstallDate=20221020203835.352020+000
InUseCount=
LastAccessed=20231115103558.131866+000
LastModified=20221020203835.352020+000
Manufacturer=Microsoft Corporation
Name=c:\windows\system32\notepad.exe
Path=\windows\system32\
Readable=TRUE
Status=OK
System=FALSE
Version=10.0.19041.1865
Writeable=TRUE

可以使用powerShell检索“产品版本”字段这:

Powershell -C "(Get-Item 'c:\\windows\\system32\\notepad.exe').VersionInfo.ProductVersion"

如果要使用批处理,则将面临将值重新作为批处理脚本中的变量的挑战。看起来这个答案描述了如何做到这一点:如何将变量从powershell传递到批处理变量

I am assuming that it is the 'Product version' field which is shown in the Details tab of the Properties dialog for the exe-file you are looking for.

This is what it looks like for C:\Windows\System32\notepad.exe:

enter image description here

Building on Qwertys comment to the original question, you can't get 'Product version' , only 'File version' (i.e. 'Version') using wmic.

Using notpad.exe as an example

The example below shows how to list all values that can be queried for using wmic,

C:\>wmic datafile where name='c:\\windows\\system32\\notepad.exe' get /value


AccessMask=1179817
Archive=TRUE
Caption=c:\windows\system32\notepad.exe
Compressed=FALSE
CompressionMethod=
CreationClassName=CIM_LogicalFile
CreationDate=20221020203835.352020+000
CSCreationClassName=Win32_ComputerSystem
CSName=PCS-SES-A
Description=c:\windows\system32\notepad.exe
Drive=c:
EightDotThreeFileName=c:\windows\system32\notepad.exe
Encrypted=FALSE
EncryptionMethod=
Extension=exe
FileName=notepad
FileSize=201216
FileType=Application
FSCreationClassName=Win32_FileSystem
FSName=NTFS
Hidden=FALSE
InstallDate=20221020203835.352020+000
InUseCount=
LastAccessed=20231115103558.131866+000
LastModified=20221020203835.352020+000
Manufacturer=Microsoft Corporation
Name=c:\windows\system32\notepad.exe
Path=\windows\system32\
Readable=TRUE
Status=OK
System=FALSE
Version=10.0.19041.1865
Writeable=TRUE

The 'Product version' field can be retrieved with Powershell like this:

Powershell -C "(Get-Item 'c:\\windows\\system32\\notepad.exe').VersionInfo.ProductVersion"

If you want to use batch-script you will have the challenge of getting the value back as a variable in your batch script. Looks like this answer describes how to do that: how to pass variable from PowerShell to batch variable

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文