Page 1 of 1

Get file version

PostPosted: Thu Feb 04, 2016 4:10 am
by stu
Hi all,

Is there a way of getting the version of an EXE file?

Sort of like using FileOpenBox and getting "1.1.0.0" of the selected file?

Re: Get file version

PostPosted: Thu Feb 04, 2016 4:30 am
by Tony Kroos
Code: Select all
    {NeoBook Function}
    Version=5,80
    Language=VBScript
    Param=[%1]|FileName|Full path to file
    Param=[%2]|Variable|Result variable
    {End}
    Set objFS = CreateObject("Scripting.FileSystemObject")
    nbSetVar "[%2]", objFS.GetFileVersion(objFS.GetFile("[%1]"))
    Set objFS = Nothing

Re: Get file version

PostPosted: Thu Feb 04, 2016 4:35 am
by stu
Tony Kroos wrote:
Code: Select all
    {NeoBook Function}
    Version=5,80
    Language=VBScript
    Param=[%1]|FileName|Full path to file
    Param=[%2]|Variable|Result variable
    {End}
    Set objFS = CreateObject("Scripting.FileSystemObject")
    nbSetVar "[%2]", objFS.GetFileVersion(objFS.GetFile("[%1]"))
    Set objFS = Nothing


Yeah, I came to ask a bit too quick... I went the vbscript way too, slightly different:

Code: Select all
' Get file version
Function GetVersion(DriveSpec)
   Dim fso, temp
   Set fso = CreateObject("Scripting.FileSystemObject")
   temp = fso.GetFileVersion(DriveSpec)
   If Len(temp) Then
      GetVersion = temp
   Else
      GetVersion = "No version information available."
   End If
End Function

publication.nbSetVar "[%2]", GetVersion("[%1]")


From here

Thanks!

Re: Get file version

PostPosted: Thu Feb 04, 2016 4:39 am
by Tony Kroos
You always make things more complex than it should )
And you may just check if [result] is empty in nb, instead of comparing it against error text strings. Keep VBS as small as possible, it takes time to execute it.

Re: Get file version

PostPosted: Thu Feb 04, 2016 6:20 am
by stu
Tony Kroos wrote:You always make things more complex than it should


You sound exactly like my ex