Advertisement
Guest User

VerTest.bas

a guest
Feb 15th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. ' version informations
  4. Private Type OSVERSIONINFOEX
  5.   dwOSVersionInfoSize       As Long
  6.   dwMajorVersion            As Long
  7.   dwMinorVersion            As Long
  8.   dwBuildNumber             As Long
  9.   dwPlatformId              As Long
  10.   szCSDVersion              As String * 128
  11.   wServicePackMajor         As Integer
  12.   wServicePackMinor         As Integer
  13.   wSuiteMask                As Integer
  14.   wProductType              As Byte
  15.   wReserved                 As Byte
  16. End Type
  17.  
  18. ' wide version for verify
  19. Private Type OSVERSIONINFOEXW
  20.   dwOSVersionInfoSize       As Long
  21.   dwMajorVersion            As Long
  22.   dwMinorVersion            As Long
  23.   dwBuildNumber             As Long
  24.   dwPlatformId              As Long
  25.   szCSDVersion(128 * 2 - 1) As Byte
  26.   wServicePackMajor         As Integer
  27.   wServicePackMinor         As Integer
  28.   wSuiteMask                As Integer
  29.   wProductType              As Byte
  30.   wReserved                 As Byte
  31. End Type
  32.  
  33. ' comparison operators
  34. Private Const VER_EQUAL = &H1
  35. Private Const VER_GREATER = &H2
  36. Private Const VER_GREATER_EQUAL = &H3
  37. Private Const VER_LESS = &H4
  38. Private Const VER_LESS_EQUAL = &H5
  39. Private Const VER_AND = &H6
  40. Private Const VER_OR = &H7
  41.  
  42. ' condition mask settings
  43. Private Const VER_CONDITION_MASK = &H7
  44. Private Const VER_NUM_BITS_PER_CONDITION_MASK = &H3
  45.  
  46. ' comparison value flags
  47. Private Const VER_MINORVERSION = &H1
  48. Private Const VER_MAJORVERSION = &H2
  49. Private Const VER_BUILDNUMBER = &H4
  50. Private Const VER_PLATFORMID = &H8
  51. Private Const VER_SERVICEPACKMINOR = &H10
  52. Private Const VER_SERVICEPACKMAJOR = &H20
  53. Private Const VER_SUITENAME = &H40
  54. Private Const VER_PRODUCT_TYPE = &H80
  55.  
  56. ' API
  57. Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As Any) As Long
  58. Private Declare Function RtlGetVersion Lib "ntdll" (ByRef lpVersionInformation As Any) As Long
  59. Private Declare Function VerSetConditionMask Lib "kernel32" (ByVal dwlConditionMask As Currency, ByVal dwTypeBitMask As Long, ByVal dwConditionMask As Byte) As Currency
  60. Private Declare Function VerifyVersionInfo Lib "kernel32" Alias "VerifyVersionInfoW" (ByRef lpVersionInfo As Any, ByVal dwTypeMask As Long, ByVal dwlConditionMask As Currency) As Long
  61.  
  62. ' storage
  63. Private mOSV1 As OSVERSIONINFOEX
  64. Private mOSV2 As OSVERSIONINFOEX
  65.  
  66. Private mRes1 As Long
  67. Private mRes2 As Long
  68.  
  69. Private mVer1 As Boolean
  70. Private mVer2 As Boolean
  71.  
  72. Sub Main()
  73.   Dim sBuffer As String
  74.  
  75.   GatherVersionInfo
  76.  
  77.   sBuffer = "GetVersionEx: rc=" & mRes1 & " version=" & mOSV1.dwMajorVersion & "." & mOSV1.dwMinorVersion & " verify=" & mVer1 & vbCrLf & _
  78.             "RtlGetVersion: rc=" & mRes2 & " version=" & mOSV2.dwMajorVersion & "." & mOSV2.dwMinorVersion & " verify=" & mVer2
  79.   MsgBox sBuffer, vbOKOnly, "Version"
  80. End Sub
  81.  
  82. Sub GatherVersionInfo()
  83.   VersionEx
  84.   If mRes1 = 0 Then
  85.     mVer1 = VerifyVersion(mOSV1.dwMajorVersion, mOSV1.dwMinorVersion)
  86.   End If
  87.   RtlVersion
  88.   If mRes2 = 0 Then
  89.     mVer2 = VerifyVersion(mOSV2.dwMajorVersion, mOSV2.dwMinorVersion)
  90.   End If
  91. End Sub
  92.  
  93. Sub VersionEx()
  94.   Dim lRet As Long
  95.   mRes1 = 0
  96.   mOSV1.dwOSVersionInfoSize = Len(mOSV1)
  97.   lRet = GetVersionEx(mOSV1)
  98.   If lRet = 0 Then
  99.     mRes1 = Err.LastDllError
  100.   End If
  101. End Sub
  102.  
  103. Sub RtlVersion()
  104.   mOSV2.dwOSVersionInfoSize = Len(mOSV2)
  105.   mRes2 = RtlGetVersion(mOSV2)
  106. End Sub
  107.  
  108. Function VerifyVersion(ByVal nMajor As Integer, ByVal nMinor As Integer) As Boolean
  109.   Dim tOSV As OSVERSIONINFOEXW
  110.   Dim dwlMask As Currency
  111.   Dim dwFlags As Long, dwResult As Long
  112.  
  113.   With tOSV
  114.     .dwOSVersionInfoSize = LenB(tOSV)
  115.     .dwMajorVersion = nMajor
  116.     .dwMinorVersion = nMinor
  117.   End With
  118.   dwlMask = VerSetConditionMask(dwlMask, VER_MAJORVERSION, VER_LESS_EQUAL)
  119.   dwlMask = VerSetConditionMask(dwlMask, VER_MINORVERSION, VER_LESS_EQUAL)
  120.   dwFlags = VER_MAJORVERSION Or VER_MINORVERSION
  121.   dwResult = VerifyVersionInfo(tOSV, dwFlags, dwlMask)
  122.   VerifyVersion = CBool(dwResult)
  123. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement