Results 1 to 17 of 17

Thread: Comparing File Version

  1. #1

    Thread Starter
    Junior Member Kop's Avatar
    Join Date
    Mar 2001
    Posts
    16

    Comparing File Version

    Hi Everyone,
    Whats the easiest way to compare the File version of 2 files and determine which one is the most recent.

    For example i have

    file 1 Version : 6.1.29.4

    file 2 Version : 6.0.32.6

    How do i determine which is the ealiest version through code.

    Thanks for ur help.

  2. #2
    PowerPoster eiSecure's Avatar
    Join Date
    Jul 2000
    Location
    Texas
    Posts
    2,209
    try loading the 2 file versions into 2 variables and try this code:
    VB Code:
    1. If File1 > File2 Then
    2.     'File1 Is Newer
    3. End If
    4.  
    5. If File1 < File2 Then
    6.     'File2 Is Newer
    7. End If
    8.  
    9. If File1 = File2 Then
    10.     'Both Are Same Version
    11. End If

  3. #3
    Addicted Member
    Join Date
    Feb 2001
    Location
    NJ
    Posts
    148
    Put this in a module
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type VS_FIXEDFILEINFO
    4.     dwSignature As Long
    5.     dwStrucVersion As Long
    6.     dwFileVersionMSl As Integer
    7.     dwFileVersionMSh As Integer
    8.     dwFileVersionLSl As Integer
    9.     dwFileVersionLSh As Integer
    10.     dwProductVersionMSl As Integer
    11.     dwProductVersionMSh As Integer
    12.     dwProductVersionLSl As Integer
    13.     dwProductVersionLSh As Integer
    14.     dwFileFlagsMask As Long
    15.     dwFileFlags As Long
    16.     dwFileOS As Long
    17.     dwFileType As Long
    18.     dwFileSubtype As Long
    19.     dwFileDateMS As Long
    20.     dwFileDateLS As Long
    21. End Type
    22.  
    23. Private Declare Function GetFileVersionInfo Lib "Version.dll" Alias _
    24.     "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwHandle As Long, ByVal _
    25.     dwLen As Long, lpData As Any) As Long
    26.  
    27. Private Declare Function GetFileVersionInfoSize Lib "Version.dll" _
    28.     Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
    29.  
    30. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, src As _
    31.     Long, ByVal length As Long)
    32.  
    33. Private Declare Function VerQueryValue Lib "Version.dll" Alias "VerQueryValueA" _
    34.     (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, puLen As Long) As Long
    35.  
    36. Public Function GetVersionInfo(ByVal sFile As String) As String
    37.  
    38.     Dim lDummy As Long
    39.     Dim sBuffer() As Byte
    40.     Dim lBufferLen As Long, lVerPointer As Long
    41.     Dim lVerBufferLen As Long
    42.     Dim udtVerBuffer As VS_FIXEDFILEINFO
    43.    
    44.     'Default return value
    45.     GetVersionInfo = "N/A"
    46.    
    47.     'Attempt to retrieve version resource
    48.     lBufferLen = GetFileVersionInfoSize(sFile, _
    49.     lDummy)
    50.    
    51.     If lBufferLen > 0 Then
    52.        
    53.         ReDim sBuffer(lBufferLen)
    54.        
    55.         If GetFileVersionInfo(sFile, 0&, _
    56.             lBufferLen, sBuffer(0)) <> 0 Then
    57.            
    58.             If VerQueryValue(sBuffer(0), _
    59.                 "\", lVerPointer, lVerBufferLen) _
    60.                 <> 0 Then
    61.        
    62.                 CopyMemory udtVerBuffer, ByVal _
    63.                     lVerPointer, Len(udtVerBuffer)
    64.                    
    65.                 With udtVerBuffer
    66.                     GetVersionInfo = _
    67.                         .dwFileVersionMSh & "." & _
    68.                         .dwFileVersionMSl & "." & _
    69.                         .dwFileVersionLSh & "." & _
    70.                         .dwFileVersionLSl
    71.                 End With
    72.        
    73.             End If
    74.         End If
    75.     End If
    76.  
    77. End Function



    ADO, SQL, Access, HTML, ASP, XML
    Visual Basic 6.0 SP5 Enterprise Edition
    VB.Net


  4. #4

    Thread Starter
    Junior Member Kop's Avatar
    Join Date
    Mar 2001
    Posts
    16
    Thanks Rossim,

    I just took out the "." and converted it to an integer and simply compared them.

    Thanks

  5. #5
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258
    Thanks Rossim,

    I just took out the "." and converted it to an integer and simply compared them.

    Thanks
    I dont think its a good Idea to take out the "."
    Because aloto of times it will be
    File1 = ver 6.1.298.6
    File2 = ver 6.1.29.87

    This way even if File1 is the later version, your check will detect File2 As Greater cause you removed the "."

  6. #6
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    I'll try to make a sub to check the version:

    VB Code:
    1. Public Sub CheckVersion(majorversion As Integer, minorversion As Integer, revisionversion As Integer)
    2. majver = majorversion
    3. minver = minorversion
    4. revver = revisionversion
    5. If App.Major < majver Then
    6.     MsgBox "out of date"
    7.     Exit Sub
    8. End If
    9. If App.Minor < minver Then
    10.     MsgBox "out of date"
    11.     Exit Sub
    12. End If
    13. If App.Revision < revver Then
    14.     MsgBox "out of date"
    15.     Exit Sub
    16. End If
    17. MsgBox "Your version is greater than or equal to the most recent version."
    18. End Sub
    19.  
    20. Private Sub Command1_Click()
    21. 'pass the sub the most recent version
    22. CheckVersion 1, 0, 0
    23. End Sub
    <removed by admin>

  7. #7

    Thread Starter
    Junior Member Kop's Avatar
    Join Date
    Mar 2001
    Posts
    16
    I guess its not as as easy as i initially thought !!!

  8. #8
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    It's not really that hard. You just need to start with the main version (2.22.3214), then if it's the same, go on to the secondary version (2.22.3214) and if that's the same, go onto the revision (2.22.3214). If that's the same, then the versions are the same, if any one of them is different then you don't have the same version.
    <removed by admin>

  9. #9
    PowerPoster eiSecure's Avatar
    Join Date
    Jul 2000
    Location
    Texas
    Posts
    2,209
    It's a lot easier if you trim out the dots (.) in the versions, and just compare to see which number is bigger.

  10. #10
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Originally posted by eiSecure
    It's a lot easier if you trim out the dots (.) in the versions, and just compare to see which number is bigger.
    It may be easier, but it may also not be as accurate.
    Posted by shragel

    I dont think its a good Idea to take out the "."
    Because aloto of times it will be
    File1 = ver 6.1.298.6
    File2 = ver 6.1.29.87
    This is why I wouldn't do it the way you said eiSecure.
    <removed by admin>

  11. #11
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258
    Thanks MidgetsBro


    EiSecure Please read all the posts before replying, Instead of playing DUMB. (Or being)..

    Serious - Read the posts before replying.

  12. #12
    PowerPoster eiSecure's Avatar
    Join Date
    Jul 2000
    Location
    Texas
    Posts
    2,209
    No, that's not what I mean. Here's what I mean:
    File1 = ver 6.1.298.6 --> 612986
    File2 = ver 6.1.29.87 --> 612987

    Now, you just compare the numbers and see which one is higher.

  13. #13
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258
    No, that's not what I mean. Here's what I mean:
    File1 = ver 6.1.298.6 --> 612986
    File2 = ver 6.1.29.87 --> 612987

    Now, you just compare the numbers and see which one is higher.
    So there you got the problem. File1 Is realy the later release - but comparing the two numbers File2 Is a higher Number.

    Understand?

  14. #14
    PowerPoster eiSecure's Avatar
    Join Date
    Jul 2000
    Location
    Texas
    Posts
    2,209
    Why on earth would a later release have a lower version number????

  15. #15
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258
    Its not a lower number.
    the File1 Miner is 298. thats larger then the minor of File2 which is 29. So even if the revision of File2 is 87 But its a revision ov version 6.1.29. So File1 is a later release.

    File1 = ver 6.1.298.6 --> 612986
    File2 = ver 6.1.29.87 --> 612987

    Understand?

  16. #16
    PowerPoster eiSecure's Avatar
    Join Date
    Jul 2000
    Location
    Texas
    Posts
    2,209
    Oohhhh....

    Gotcha! Sorry about that!

  17. #17
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    Here is another sub I made, that splits the version by . and checks each part of the string. You can modify it to do whatever you want when it find that the version is lower or higher.

    VB Code:
    1. Public Sub CompareVersions(ver1 As String, ver2 As String)
    2. Dim varray1() As String
    3. Dim varray2() As String
    4. varray1() = Split(ver1, ".")
    5. varray2() = Split(ver2, ".")
    6. '---CHECK MAJOR BUILDS---
    7. If Val(varray1(0)) > Val(varray2(0)) Then
    8.     'version one major build is greater than version two
    9.     'exit sub
    10. ElseIf Val(varray1(0)) < Val(varray2(0)) Then
    11.     'version two major build is greater than version one
    12.     'exit sub
    13. Else
    14.     'major builds are equal
    15.     'continue?
    16. End If
    17. '---CHECK MINOR BUILDS---
    18. If Val(varray1(1)) > Val(varray2(1)) Then
    19.     'version one minor build is greater than version two
    20.     'exit sub
    21. ElseIf Val(varray1(1)) < Val(varray2(1)) Then
    22.     'version two minor build is greater than version one
    23.     'exit sub
    24. Else
    25.     'minor builds are equal
    26.     'continue?
    27. End If
    28. '---CHECK REVISION BUILDS---
    29. If Val(varray1(2)) > Val(varray2(2)) Then
    30.     'version one revision build is greater than version two
    31.     'exit sub
    32. ElseIf Val(varray1(2)) < Val(varray2(2)) Then
    33.     'version two revision build is greater than version one
    34.     'exit sub
    35. Else
    36.     'revision builds are equal
    37.     'continue?
    38. End If
    39. End Sub
    <removed by admin>

Posting Permissions

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



Click Here to Expand Forum to Full Width