Get the "File version" of an exe file

13 ビュー (過去 30 日間)
David Goldfisher
David Goldfisher 2022 年 12 月 28 日
編集済み: Wolfie 2025 年 8 月 27 日
How can I get the "File version" or the "Product version" of an exe file?
i can see it if:
  1. i'm right click on the exe file.
  2. click on "Properties".
  3. click on TAB "Details".
  4. under the "Description" title are listed the parameters "File version" and "Product version".
I want to read these parameters using a Matlab command.
I saw a way to get the "Owner" of the file using the commands in the link below, but I couldn't figure out how to read the "File version".

採用された回答

Jan
Jan 2022 年 12 月 28 日
編集済み: Jan 2022 年 12 月 28 日
Create a VBS script:
' File: FileProductVer.vbs
Set FSO=CreateObject("Scripting.FileSystemObject")
If Wscript.Arguments.Count > 0 then
sFullFileName = Wscript.Arguments(0)
If FSO.FileExists(sFullFileName) Then
Set objFolder = CreateObject("Shell.Application").Namespace(FSO.GetParentFolderName(sFullFileName))
Set objFolderItem = objFolder.ParseName(FSO.GetFileName(sFullFileName))
WScript.Echo "FileVersion : " & objFolderItem.ExtendedProperty("Fileversion")
WScript.Echo "ProductVersion: " & objFolderItem.ExtendedProperty("productversion")
Else
WScript.Echo "Error: missing file"
End If
Else
WScript.Echo "Error: missing input"
End If
Then call it from Matlab:
file = fullfile(matlabroot, 'bin', 'matlab.exe');
[status, result] = system(sprintf('cscript -nologo FileProductVer.vbs "%s"', file))
Output:
result =
'FileVersion : 1.0.0.1
ProductVersion: 9.5.0.878302
'
Parse this using strsplit and strtrim.
  1 件のコメント
David Goldfisher
David Goldfisher 2022 年 12 月 28 日
Thank you very much, this helped me a lot!
For those who do not know how to work with the VBS script:
You can open a txt file and copy the VBS script into it.
Then rename the file to "FileProductVer.vbs"

サインインしてコメントする。

その他の回答 (1 件)

Wolfie
Wolfie 2025 年 8 月 27 日
編集済み: Wolfie 2025 年 8 月 27 日
You can use .NET functionality directly. Here is the Microsoft documentation for the System.Diagnostics.FileVersionInfo function:
MATLAB code:
file = fullfile(matlabroot, 'bin', 'matlab.exe');
v = char( System.Diagnostics.FileVersionInfo.GetVersionInfo( file ).FileVersion );
Output:
v =
'24.2.0.2651190'
If you don't use the .FileVersion attribute then you'll get a structure with various fields including numeric major/minor versions.

カテゴリ

Help Center および File ExchangeCall Web Services from MATLAB Using HTTP についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by