Hi,
Have any way to get file version?
For example, get version of the file "c:\windows\notepad.exe"
Thank you.
HOWTO Get file version ? [SOLVED]
HOWTO Get file version ? [SOLVED]
Last edited by Haruks on Fri May 07, 2010 2:10 am, edited 1 time in total.
=D
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: HOWTO Get file version ?
I'm afraid this isn't something that is native in Purebasic. However, as PB has unlimited access to the Windows API, it can be managed with a few imports and some API coding. I made this demo for you, I hope it helps:
As you can see, there really isn't much to it. Perhaps someday the Purebasic team will make some native commands for it. If it's important to you, you can make a feature request. They do read and consider all of them.
Code: Select all
;///////////////////////////////////////////////////////////////////
;
; Demo: Windows API File Version Info
; Author: Lloyd Gallant (netmaestro)
; Date: May 06, 2010
; Target Compiler: PureBasic 4.20 and later
; Target OS: Microsoft Windows All (x86)
; License: Free, no restrictions, no warranty whatsoever
;
;//////////////////////////////////////////////////////////////////
Pattern$ = "Executables (*.exe)|*.exe;|Dynamic Link Library (*.dll)|*.dll;|All files (*.*)|*.*"
Filename$ = OpenFileRequester("Please choose file to load", "", Pattern$, 0)
Import "version.lib"
GetFileVersionInfoSizeA( *lptstrFilename, *lpdwHandle )
GetFileVersionInfoA( *lptstrFilename, dwHandle, dwLen, *lpData)
VerQueryValueA( *pBlock, *lpSubBlock, *lplpBuffer, *puLen)
EndImport
Global Dim Stringname$(12)
Restore stringnames
For i=1 To 12
Read$ Stringname$(i)
Next
Structure LANGANDCODEPAGE
wLanguage.w
wCodePage.w
EndStructure
infosize = GetFileVersionInfoSizeA( @filename$, @handle.i)
If infosize
*lpData = AllocateMemory(infosize)
If GetFileVersionInfoA( @filename$, 0, infosize, *lpdata)
If VerQueryValueA( *lpdata, @"\VarFileInfo\Translation", @*lplpBuffer, @puLen)
*readptr.LANGANDCODEPAGE = *lplpBuffer
For i=0 To puLen/SizeOf(LANGANDCODEPAGE) - 1
langandcodepage$ = RSet(Hex(*readptr\wLanguage),4,"0") + RSet(Hex(*readptr\wCodePage), 4, "0")
For j=1 To 12
SubBlock$ ="\\StringFileInfo\\" + langandcodepage$ + "\\" + Stringname$(j)
If VerQueryValueA( *lpdata, @SubBlock$, @*stringbuffer, @Bytes) And Bytes
Debug Stringname$(j)+": "+PeekS(*stringbuffer, Bytes)
EndIf
Next
*readptr + SizeOf(LANGANDCODEPAGE)
Next
EndIf
Else
Debug "No version information available"
EndIf
FreeMemory(*lpData)
Else
Debug "No version information available"
EndIf
DataSection
stringnames:
Data.s "Comments", "InternalName", "ProductName"
Data.s "CompanyName", "LegalCopyright", "ProductVersion"
Data.s "FileDescription", "LegalTrademarks", "PrivateBuild"
Data.s "FileVersion", "OriginalFilename", "SpecialBuild"
EndDataSection
Last edited by netmaestro on Fri May 07, 2010 2:52 am, edited 2 times in total.
BERESHEIT
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: HOWTO Get file version ? (n,n,n,n)
Hello,
I was searching for an API to get the version of the executable created with PB, and found this. However, it does not return the info I need to get.
In PureBasic (v.5.00), Compiler/Compiler Options.../ under the tab "Version Info", we have the two first parameters:
File Version (n,n,n,n)
Product Version (n,n,n,n)
Can netmaestro's program be updated to get them as well?
Thanks in advance!
PS: The file version we see when we run this program are the 5th and 6th parameters!
I was searching for an API to get the version of the executable created with PB, and found this. However, it does not return the info I need to get.

In PureBasic (v.5.00), Compiler/Compiler Options.../ under the tab "Version Info", we have the two first parameters:
File Version (n,n,n,n)
Product Version (n,n,n,n)
Can netmaestro's program be updated to get them as well?
Thanks in advance!
PS: The file version we see when we run this program are the 5th and 6th parameters!
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Re: HOWTO Get file version ? [SOLVED]
Yeah, I noticed this too.
The IDE - Version Info Tab states "Fields marked with * are required."
So, you have to enter your FileVersion and ProductVersion into the 5th and 6th parameters also.
I found the values in the 1st 2 fields are placed in the resource block and are read differently from the code posted above.
Read/Set File Version in Resource Block
No benefit to reading this though, since they should be identical.
The IDE - Version Info Tab states "Fields marked with * are required."
So, you have to enter your FileVersion and ProductVersion into the 5th and 6th parameters also.
I found the values in the 1st 2 fields are placed in the resource block and are read differently from the code posted above.
Read/Set File Version in Resource Block
No benefit to reading this though, since they should be identical.

The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: HOWTO Get file version ? (n,n,n,n)
Thanks Skywalk,
True, but as the PureBasic manual explained, the 5th param (ProductVersion) should read "v4" for example, and the 6th param (FileVersion) as "4.0".
(see PureBasic Help, tab "Search", find "Compiling your programs" and scroll until you see the screenshot of "Version Info").
But thanks to your link, I found that one of the elements we need is dwFileVersionMS, so I searched the internet, and found this page: http://fgaillard.com/2012/08/reading-ve ... -your-exe/, so maybe you or someone else can translate it to PureBasic? I think it is Delphi code... It would be great to enrich PB with this valuable info...
True, but as the PureBasic manual explained, the 5th param (ProductVersion) should read "v4" for example, and the 6th param (FileVersion) as "4.0".
(see PureBasic Help, tab "Search", find "Compiling your programs" and scroll until you see the screenshot of "Version Info").
But thanks to your link, I found that one of the elements we need is dwFileVersionMS, so I searched the internet, and found this page: http://fgaillard.com/2012/08/reading-ve ... -your-exe/, so maybe you or someone else can translate it to PureBasic? I think it is Delphi code... It would be great to enrich PB with this valuable info...

- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Re: HOWTO Get file version ? [SOLVED]
You can found a translated version here: http://www.purebasic.fr/english/viewtop ... 17#p323517 
And yes, it is Delphi

And yes, it is Delphi
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: HOWTO Get file version ? [SOLVED]


Never mind, I finally found the code in PureBasic by searching further : http://www.purebasic.fr/english/viewtop ... MS#p308752
And this one works great! OK, it displays only the FileVersion (1st param), but that's okay to me, as it is what we see in the properties of the EXE file through the Explorer.
Thank you for your time!
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%