Solved

File Properties -> Version Number

Posted on 2002-05-30
5
3,487 Views
Last Modified: 2008-08-27
Hi there!

You know when you right-click a file on explorer, select properties and then check its version number on the "version" tab of the properties dialog?

Well, how can I do the same from my VB app? i.e., get a file's version number programmatically?

Note: I rather steer away from adding more dependencies to my app, a API-only solution would be a bless :-)

Thanks and have a nice day!
Claudio
0
Comment
Question by:ca_heckler
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7044547
from the Project Properties, into the Make tab, you have the version number and an option to auto-increment it.
0
 
LVL 1

Author Comment

by:ca_heckler
ID: 7044567
No ofense meant, but could you read the *question* again?
What I want is to programmatically get the version for any generic file.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
ID: 7044605
I think with the below function (GetFileInfo) you get what you need. The declare function are the API requirements for the function (i hope i didn't miss any as i copied out of my application code)

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)

Private Declare Function lstrcpy Lib "kernel32" _
   Alias "lstrcpyA" _
   (ByVal lpString1 As String, _
   ByVal lpString2 As Long) As Long


Public Sub GetFileInfo(strFile As String, ByRef filDate As Date, _
  ByRef filVersion As String, ByRef filLanguage As Long)
 
  Dim lBufferLen As Long
  Dim lDummy As Long
  Dim sBuffer()  As Byte
  Dim bytebuffer(255) As Byte
  Dim lVerPointer As Long
  Dim Lang_Charset_String As String
  Dim HexNumber As Long

  Dim strTemp As String
  Dim strBuffer As String
 
  Dim rc As Long
 
  lBufferLen = GetFileVersionInfoSize(strFile, lDummy)
  If lBufferLen > 0 Then
 
    ReDim sBuffer(lBufferLen)
    rc = GetFileVersionInfo(strFile, 0&, _
                             lBufferLen, _
                             sBuffer(0))
    If rc <> 0 Then
      rc = VerQueryValue(sBuffer(0), "\VarFileInfo\Translation", _
                        lVerPointer, _
                        lBufferLen)
                       
      MoveMemory bytebuffer(0), lVerPointer, lBufferLen
      HexNumber = bytebuffer(2) + bytebuffer(3) * &H100 + _
                  bytebuffer(0) * &H10000 + bytebuffer(1) * &H1000000
      Lang_Charset_String = Hex(HexNumber)
      Do While Len(Lang_Charset_String) < 8
         Lang_Charset_String = "0" & Lang_Charset_String
      Loop
           
           
      strBuffer = String(255, 0)
      strTemp = "\StringFileInfo\" & Lang_Charset_String _
        & "\FileVersion"
      rc = VerQueryValue(sBuffer(0), strTemp, _
                          lVerPointer, lBufferLen)

      lstrcpy strBuffer, lVerPointer
      strBuffer = Mid$(strBuffer, 1, InStr(strBuffer, Chr(0)) - 1)
           
      filLanguage = HexNumber
      filDate = FileDateTime(strFile)
      filVersion = strBuffer
    Else
      filDate = Empty
      filVersion = ""
      filLanguage = 0
    End If
  Else
    filDate = Empty
    filVersion = ""
    filLanguage = 0
  End If
End Sub



CHeers
0
 
LVL 1

Author Comment

by:ca_heckler
ID: 7044636
Awesome! You're da man, thanks!
0
 

Expert Comment

by:Derek0903
ID: 12622415
Thanks - this code is great - saved me a bunch of time..

Cheers..
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month4 days, 18 hours left to enroll

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question