Get Major,Minor & Rev. Versions From App

How do you get the version information from an exe for Major,Minor & Rev. The Exe's are vb that ive made.
Who is Participating?

Try something like that. It works for exe, dlls and ocxs.


Remember to add Microsoft Scripting Runtime reference.

Option Explicit

Private Sub GetVersion(sFileName As String, sMajor As String, sMinor As String, sRevision As String)

    Dim oFS As New FileSystemObject
    Dim asValues() As String
    asValues = Split(oFS.GetFileVersion(sFileName), ".")
    If UBound(asValues) = 3 Then
        sMajor = asValues(0)
        sMinor = asValues(1)
        sRevision = asValues(3)
    End If

    Set oFS=nothing

End Sub

Private Sub Form_Load()

    Dim sMajor As String, sMinor As String, sRevision As String
    Call GetVersion("c:\Proyect1.exe", sMajor, sMinor, sRevision)
    MsgBox "Major=" & sMajor & vbCrLf & "Minor=" & sMinor & vbCrLf & "Revision=" & sRevision

End Sub
thaburnerAuthor Commented:
I know that lol, sorry i guess i wasnt very clear. Im running App1.exe & i want to know what the Version of App2.exe is
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

thaburnerAuthor Commented:
Im running App1 & with out running App2 i want to find the Version of the file from app1 along with ocx & dll files
Here is an sample (trimmed to be specific to file version):
   dwSignature As Long
   dwStrucVersionl As Integer     '  e.g. = &h0000 = 0
   dwStrucVersionh As Integer     '  e.g. = &h0042 = .42
   dwFileVersionMSl As Integer    '  e.g. = &h0003 = 3
   dwFileVersionMSh As Integer    '  e.g. = &h0075 = .75
   dwFileVersionLSl As Integer    '  e.g. = &h0000 = 0
   dwFileVersionLSh As Integer    '  e.g. = &h0031 = .31
   dwProductVersionMSl As Integer '  e.g. = &h0003 = 3
   dwProductVersionMSh As Integer '  e.g. = &h0010 = .1
   dwProductVersionLSl As Integer '  e.g. = &h0000 = 0
   dwProductVersionLSh As Integer '  e.g. = &h0031 = .31
   dwFileFlagsMask As Long        '  = &h3F for version "0.42"
   dwFileFlags As Long            '  e.g. VFF_DEBUG Or VFF_PRERELEASE
   dwFileOS As Long               '  e.g. VOS_DOS_WINDOWS16
   dwFileType As Long             '  e.g. VFT_DRIVER
   dwFileSubtype As Long          '  e.g. VFT2_DRV_KEYBOARD
   dwFileDateMS As Long           '  e.g. 0
   dwFileDateLS As Long           '  e.g. 0
End Type
Private Declare Function GetFileVersionInfo Lib "Version.dll" Alias "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwhandle As Long, ByVal dwlen As Long, lpData As Any) As Long
Private Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
Private Declare Function VerQueryValue Lib "Version.dll" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, puLen As Long) As Long
Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, ByVal Source As Long, ByVal length As Long)
Dim Filename As String, Directory As String, FullFileName As String
Dim StrucVer As String, FileVer As String, ProdVer As String
Dim FileFlags As String, FileOS As String, FileType As String, FileSubType As String
Private Sub DisplayVerInfo()
   Dim rc As Long, lDummy As Long, sBuffer() As Byte
   Dim lBufferLen As Long, lVerPointer As Long, udtVerBuffer As VS_FIXEDFILEINFO
   Dim lVerbufferLen As Long

   '*** Get size ****
   lBufferLen = GetFileVersionInfoSize(FullFileName, lDummy)
   If lBufferLen < 1 Then
      MsgBox "No Version Info available!"
      Exit Sub
   End If

   '**** Store info to udtVerBuffer struct ****
   ReDim sBuffer(lBufferLen)
   rc = GetFileVersionInfo(FullFileName, 0&, lBufferLen, sBuffer(0))
   rc = VerQueryValue(sBuffer(0), "\", lVerPointer, lVerbufferLen)
   MoveMemory udtVerBuffer, lVerPointer, Len(udtVerBuffer)

   '**** Determine Structure Version number - NOT USED ****
   StrucVer = Format$(udtVerBuffer.dwStrucVersionh) & "." & Format$(udtVerBuffer.dwStrucVersionl)

   '**** Determine File Version number ****
   FileVer = Format$(udtVerBuffer.dwFileVersionMSh) & "." & Format$(udtVerBuffer.dwFileVersionMSl) & "." & Format$(udtVerBuffer.dwFileVersionLSh) & "." & Format$(udtVerBuffer.dwFileVersionLSl)

End Sub
Private Sub Form_Load()
    'KPD-Team 2000
    'Source -> MS Knowledge Base
    'set the file
    Filename = "kernel32.dll"
    Directory = "c:\winnt\system32\"
    FullFileName = Directory + Filename
    'set graphics mode to persistent
    Me.AutoRedraw = True
    'retrieve the information
    'show the results
    Me.Print "Full filename: " + FullFileName
    Me.Print "File version: " + FileVer
End Sub

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.