Looking for a method to read file version information for an .exe file on Windows and an .app file on Mac. Trying to read the file without opening the file. This is for an update application that will need to look for a new version and update itself. Will need to switch over to the updated application but needs to look at the version number to make sure it is the newest one. Trying to not include the version in the file name like Updater 18.1. Just want it to be Updater and read the version information. Any help would be great.
If I understand your needs correctly, have you looked at Kaju?
for macOS use the MDLS terminal command, it will have the version # assuming one has been assigned
[quote=391592:@Kem Tekinay]If I understand your needs correctly, have you looked at Kaju?
No, just trying to build my own updater. Not ready to go with an add on yet. Just need to overcome this last hurdle and then it will be working. But thanks for the suggestion.
Here’s the windows version, call it like this:
Dim f As New FolderItem("C:\\Program Files\\Xojo\\Xojo 2018r1.1\\Xojo.exe")
Dim version As String
version = GetFileVersion(f)
[code]Public Function GetFileVersion(filename As FolderItem) as String
Dim h As UInt32
Dim versionSize As UInt32
Soft Declare Function GetFileVersionInfoSize Lib “Api-ms-win-core-version-l1-1-0.dll” Alias “GetFileVersionInfoSizeW” (lptstrFilename As WString, ByRef lpdwHandle As UInt32) As UInt32
versionSize = GetFileVersionInfoSize(filename.NativePath, h)
If versionSize > 0 Then
Dim ok As Int32
Dim mb As New MemoryBlock(versionSize)
'https://msdn.microsoft.com/en-us/library/windows/desktop/ms647003(v=vs.85).aspx Soft Declare Function GetFileVersionInfo Lib "Api-ms-win-core-version-l1-1-0.dll" Alias "GetFileVersionInfoW" (lptstrFilename As WString, dwHandle As UInt32, dwLen As UInt32, lpData As Ptr) As Int32 ok = GetFileVersionInfo(filename.NativePath, 0, versionSize, mb) If ok <> 0 Then 'https://msdn.microsoft.com/en-us/library/windows/desktop/ms647464(v=vs.85).aspx Soft Declare Function VerQueryValue Lib "Api-ms-win-core-version-l1-1-0.dll" Alias "VerQueryValueW" (pBlock As Ptr, lpSubBlock As WString, ByRef lplpBuffer As Ptr, ByRef puLen As UInt32) As Int32 Dim pos As Ptr Dim l As UInt32 'Get the lang-codepage out of the file Dim langcodepage As String If VerQueryValue(mb, "\\\\VarFileInfo\\\\Translation", pos, l) <> 0 Then Dim pp As Ptr pp = mb Const prefix = "00000000" langcodepage = right(prefix + hex(mb.UInt16Value(pos - pp)), 4) + right(prefix + hex(mb.UInt16Value(pos - pp + 2)), 4) system.debuglog("langcodepage=" + langcodepage) End If 'Get the ProductVersion out of the file 'Might need to change this from ProductVersion to FileVersion depending how the information it stored. If VerQueryValue(mb, "\\\\StringFileInfo\\\" + langcodepage + "\\\\ProductVersion", pos, l) <> 0 Then Dim pp As Ptr pp = mb 'Return the version if we've found it Return mb.WString(pos - pp) End If End If
'Return “” if something went wrong
If I understand the problem, Main app downloads Update app, then wants to confirm that it’s a later version. If so, it switches to Update app, right?
Suggestion: as part of your build script, include a file with the version info in a known location like the Resources folder. Main app only has to find and read it