B4J Question File (exe) properties

Drago Bratko

Active Member
Licensed User
Longtime User
Is there a way to read file properties of a exe file?
By file properties, I mean data which is visible when you right click on a exe file, click on "Properties", and then click on "Details" tab. What I would like to read is "File version" or "Product version" property.
That exe file (which I would like to read properties) is created from jar with launch4j.exe
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Yes.
Copy the attached file to the additional libraries folder.
License: https://github.com/kichik/pecoff4j/blob/master/cpl-v10.html

B4X:
#AdditionalJar: pecoff4j
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.Show
   ParseResource("C:\Program Files (x86)\Anywhere Software\B4J\B4J.exe")
End Sub

Sub ParseResource(Path As String)
   Dim PEParser As JavaObject
   Dim PE As JavaObject = PEParser.InitializeStatic("org.boris.pecoff4j.io.PEParser").RunMethod("parse", Array(Path))
   Dim rd As JavaObject = PE.RunMethodJO("getImageData", Null).RunMethod("getResourceTable", Null)
   Dim ResourceType, ResouceHelper, ResourceParser As JavaObject
   ResourceType.InitializeStatic("org.boris.pecoff4j.constant.ResourceType")
   ResouceHelper.InitializeStatic("org.boris.pecoff4j.util.ResourceHelper")
   ResourceParser.InitializeStatic("org.boris.pecoff4j.io.ResourceParser")
   Dim entries() As Object = ResouceHelper.RunMethod("findResources", Array(rd, ResourceType.GetField("VERSION_INFO")))
   For Each entry As JavaObject In entries
       Dim version As JavaObject = ResourceParser.RunMethod("readVersionInfo", Array(entry.RunMethod("getData", Null)))
       Dim strings As JavaObject = version.RunMethod("getStringFileInfo", Null)
       Dim table As JavaObject = strings.RunMethod("getTable", Array(0))
       For j = 0 To table.RunMethod("getCount", Null) - 1
           Dim key As String = table.RunMethodJO("getString", Array(j)).RunMethod("getKey", Null)
           Dim value As String = table.RunMethodJO("getString", Array(j)).RunMethod("getValue", Null)
           Log($"${key}: ${value}"$)
       Next
   Next
End Sub

Output:
Comments: B4J
CompanyName: Anywhere Software
FileDescription: B4J
FileVersion: 6.0.0.0
InternalName: B4J.exe
LegalCopyright: Anywhere Software
LegalTrademarks: Anywhere Software
OriginalFilename: B4J.exe
ProductName: B4J
ProductVersion: 6.0.0.0
Assembly Version: 6.0.0.0
 

Attachments

  • pecoff4j.jar
    113.7 KB · Views: 215
Upvote 0
Top