[RESOLVED] Get EXE Version-VBForums
Results 1 to 8 of 8

Thread: [RESOLVED] Get EXE Version

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2007
    Posts
    278

    Resolved [RESOLVED] Get EXE Version

    Is there any simple way how can I get version from other *.EXE file?

  2. #2
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,474

    Re: Get EXE Version

    You can use the File System Object but it will require you to distribute the dll for it in your package.

    Code:
    Option Explicit
    'Add a reference to Microsoft Scripting Runtime
    Private Sub Form_Load()
        Dim fso As FileSystemObject
        Set fso = New FileSystemObject
        MsgBox fso.GetFileVersion("C:\Program Files\Microsoft Visual Studio\VB98\VB6.EXE")
    End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Corsair H100i v2 water cooler, Geforce GTX1060, Samsung 500 GB SSD, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2010, VS 2010

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Get EXE Version

    Here is an API approach.
    Not my code. I can't even remember where I got it.

    Code:
    Option Explicit
    
    Public Type VS_FIXEDFILEINFO
       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
    
    
    'Windows API function declarations
    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    
    Public 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
    Public Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
    Public Declare Function VerQueryValue Lib "Version.dll" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, puLen As Long) As Long
    
    
    Public Function GetFileVersion(ByVal FileName As String) As String
       Dim nDummy As Long
       Dim sBuffer()         As Byte
       Dim nBufferLen        As Long
       Dim lplpBuffer       As Long
       Dim udtVerBuffer      As VS_FIXEDFILEINFO
       Dim puLen     As Long
          
       nBufferLen = GetFileVersionInfoSize(FileName, nDummy)
       
       If nBufferLen > 0 Then
       
            ReDim sBuffer(nBufferLen) As Byte
            Call GetFileVersionInfo(FileName, 0&, nBufferLen, sBuffer(0))
            Call VerQueryValue(sBuffer(0), "\", lplpBuffer, puLen)
            Call CopyMemory(udtVerBuffer, ByVal lplpBuffer, Len(udtVerBuffer))
            
            GetFileVersion = udtVerBuffer.dwFileVersionMSh & "." & udtVerBuffer.dwFileVersionMSl & "." & udtVerBuffer.dwFileVersionLSh & "." & udtVerBuffer.dwFileVersionLSl
      
        End If
    End Function

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2007
    Posts
    278

    Re: Get EXE Version

    Thanks!

  5. #5
    Junior Member
    Join Date
    Jul 2013
    Posts
    27

    Re: Get EXE Version

    Quote Originally Posted by brucevde View Post
    Here is an API approach.
    Not my code. I can't even remember where I got it.

    Code:
    Option Explicit
    
    Public Type VS_FIXEDFILEINFO
       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
    
    
    'Windows API function declarations
    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    
    Public 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
    Public Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
    Public Declare Function VerQueryValue Lib "Version.dll" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, puLen As Long) As Long
    
    
    Public Function GetFileVersion(ByVal FileName As String) As String
       Dim nDummy As Long
       Dim sBuffer()         As Byte
       Dim nBufferLen        As Long
       Dim lplpBuffer       As Long
       Dim udtVerBuffer      As VS_FIXEDFILEINFO
       Dim puLen     As Long
          
       nBufferLen = GetFileVersionInfoSize(FileName, nDummy)
       
       If nBufferLen > 0 Then
       
            ReDim sBuffer(nBufferLen) As Byte
            Call GetFileVersionInfo(FileName, 0&, nBufferLen, sBuffer(0))
            Call VerQueryValue(sBuffer(0), "\", lplpBuffer, puLen)
            Call CopyMemory(udtVerBuffer, ByVal lplpBuffer, Len(udtVerBuffer))
            
            GetFileVersion = udtVerBuffer.dwFileVersionMSh & "." & udtVerBuffer.dwFileVersionMSl & "." & udtVerBuffer.dwFileVersionLSh & "." & udtVerBuffer.dwFileVersionLSl
      
        End If
    End Function
    Can you give me a sample call for this API approach? As API is the fastest way to do it.

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,107

    Re: [RESOLVED] Get EXE Version

    WHo are you asking? Someone from this 2008 thread?

  7. #7
    Junior Member
    Join Date
    Jul 2013
    Posts
    27

    Re: [RESOLVED] Get EXE Version

    Yes, but if you know a sample call for this then you can post it.

  8. #8
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,346

    Re: [RESOLVED] Get EXE Version

    This is how to call the function in post #3

    vb Code:
    1. MsgBox ("File version is " & GetFileVersion(App.EXEName & ".exe"))
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    Please consider giving me some rep points if I help you a lot.
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.