|
-
Jul 25th, 2001, 03:15 PM
#1
Thread Starter
Junior Member
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.
-
Jul 25th, 2001, 03:18 PM
#2
PowerPoster
try loading the 2 file versions into 2 variables and try this code:
VB Code:
If File1 > File2 Then
'File1 Is Newer
End If
If File1 < File2 Then
'File2 Is Newer
End If
If File1 = File2 Then
'Both Are Same Version
End If
-
Jul 25th, 2001, 03:19 PM
#3
Addicted Member
Put this in a module
VB Code:
Option Explicit
Private Type VS_FIXEDFILEINFO
dwSignature As Long
dwStrucVersion As Long
dwFileVersionMSl As Integer
dwFileVersionMSh As Integer
dwFileVersionLSl As Integer
dwFileVersionLSh As Integer
dwProductVersionMSl As Integer
dwProductVersionMSh As Integer
dwProductVersionLSl As Integer
dwProductVersionLSh As Integer
dwFileFlagsMask As Long
dwFileFlags As Long
dwFileOS As Long
dwFileType As Long
dwFileSubtype As Long
dwFileDateMS As Long
dwFileDateLS As Long
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 Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, src As _
Long, ByVal length 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
Public Function GetVersionInfo(ByVal sFile As String) As String
Dim lDummy As Long
Dim sBuffer() As Byte
Dim lBufferLen As Long, lVerPointer As Long
Dim lVerBufferLen As Long
Dim udtVerBuffer As VS_FIXEDFILEINFO
'Default return value
GetVersionInfo = "N/A"
'Attempt to retrieve version resource
lBufferLen = GetFileVersionInfoSize(sFile, _
lDummy)
If lBufferLen > 0 Then
ReDim sBuffer(lBufferLen)
If GetFileVersionInfo(sFile, 0&, _
lBufferLen, sBuffer(0)) <> 0 Then
If VerQueryValue(sBuffer(0), _
"\", lVerPointer, lVerBufferLen) _
<> 0 Then
CopyMemory udtVerBuffer, ByVal _
lVerPointer, Len(udtVerBuffer)
With udtVerBuffer
GetVersionInfo = _
.dwFileVersionMSh & "." & _
.dwFileVersionMSl & "." & _
.dwFileVersionLSh & "." & _
.dwFileVersionLSl
End With
End If
End If
End If
End Function
-
Jul 25th, 2001, 03:37 PM
#4
Thread Starter
Junior Member
Thanks Rossim,
I just took out the "." and converted it to an integer and simply compared them.
Thanks
-
Jul 25th, 2001, 03:50 PM
#5
Frenzied Member
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 "."
-
Jul 25th, 2001, 04:11 PM
#6
PowerPoster
I'll try to make a sub to check the version:
VB Code:
Public Sub CheckVersion(majorversion As Integer, minorversion As Integer, revisionversion As Integer)
majver = majorversion
minver = minorversion
revver = revisionversion
If App.Major < majver Then
MsgBox "out of date"
Exit Sub
End If
If App.Minor < minver Then
MsgBox "out of date"
Exit Sub
End If
If App.Revision < revver Then
MsgBox "out of date"
Exit Sub
End If
MsgBox "Your version is greater than or equal to the most recent version."
End Sub
Private Sub Command1_Click()
'pass the sub the most recent version
CheckVersion 1, 0, 0
End Sub
-
Jul 25th, 2001, 05:28 PM
#7
Thread Starter
Junior Member
I guess its not as as easy as i initially thought !!!
-
Jul 25th, 2001, 05:52 PM
#8
PowerPoster
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.
-
Jul 25th, 2001, 05:58 PM
#9
PowerPoster
It's a lot easier if you trim out the dots (.) in the versions, and just compare to see which number is bigger.
-
Jul 25th, 2001, 10:50 PM
#10
PowerPoster
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.
-
Jul 25th, 2001, 11:34 PM
#11
Frenzied Member
Thanks MidgetsBro
EiSecure Please read all the posts before replying, Instead of playing DUMB. (Or being)..
Serious - Read the posts before replying.
-
Jul 26th, 2001, 12:44 PM
#12
PowerPoster
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.
-
Jul 26th, 2001, 01:36 PM
#13
Frenzied Member
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?
-
Jul 26th, 2001, 01:42 PM
#14
PowerPoster
Why on earth would a later release have a lower version number????
-
Jul 26th, 2001, 02:16 PM
#15
Frenzied Member
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?
-
Jul 26th, 2001, 02:18 PM
#16
PowerPoster
Oohhhh....
Gotcha! Sorry about that!
-
Jul 26th, 2001, 04:29 PM
#17
PowerPoster
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:
Public Sub CompareVersions(ver1 As String, ver2 As String)
Dim varray1() As String
Dim varray2() As String
varray1() = Split(ver1, ".")
varray2() = Split(ver2, ".")
'---CHECK MAJOR BUILDS---
If Val(varray1(0)) > Val(varray2(0)) Then
'version one major build is greater than version two
'exit sub
ElseIf Val(varray1(0)) < Val(varray2(0)) Then
'version two major build is greater than version one
'exit sub
Else
'major builds are equal
'continue?
End If
'---CHECK MINOR BUILDS---
If Val(varray1(1)) > Val(varray2(1)) Then
'version one minor build is greater than version two
'exit sub
ElseIf Val(varray1(1)) < Val(varray2(1)) Then
'version two minor build is greater than version one
'exit sub
Else
'minor builds are equal
'continue?
End If
'---CHECK REVISION BUILDS---
If Val(varray1(2)) > Val(varray2(2)) Then
'version one revision build is greater than version two
'exit sub
ElseIf Val(varray1(2)) < Val(varray2(2)) Then
'version two revision build is greater than version one
'exit sub
Else
'revision builds are equal
'continue?
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|