Reference:
https://stackoverflow.com/questions/50910593/understanding-this-compare-function-vbscript
https://www.oreilly.com/library/view/vbscript-in-a/1565927206/re83.html
Dim fso, f Set fso = CreateObject("Scripting.FileSystemObject") 'Set f = fso.GetFile("C:\user.js") current_version=fso.GetFileVersion("C:\Program Files\VideoLAN\VLC\vlc.exe") MsgBox(current_version) MsgBox(CompareFileVersion(current_version, "3.0.16.0")) Public Function CompareFileVersion(strFileVersion1, strFileVersion2) ' Our result ' -1 = File Version 2 is greater than File Version 1 ' 0 = Versions are the same ' 1 = File version 1 is greater than File Version 2 Dim intResult Dim strAryFileVersion1 Dim strAryFileVersion2 ' Let's initialize our result with 0 intResult = 0 'Split the two supplied file versions by the "." character strAryFileVersion1 = Split(strFileVersion1, ".") strAryFileVersion2 = Split(strFileVersion2, ".") For i = 0 To UBound(strAryFileVersion1) If strAryFileVersion1(i) > strAryFileVersion2(i) Then intResult = 1 ElseIf strAryFileVersion1(i) < strAryFileVersion2(i) Then intResult = -1 End If 'If we have found that the result is not > or <, no need to proceed If intResult <> 0 Then Exit For Next If UBound(strAryFileVersion2) > UBound(strAryFileVersion1) _ And strAryFileVersion2(UBound(strAryFileVersion2)) <> 0 Then intResult = -1 CompareFileVersion = intResult End Function
No comments:
Post a Comment