Autor Tema: Averiguar versión de ADO  (Leído 3397 veces)

Desconectado xavi

  • Administrador
  • Habitual
  • *****
  • Mensajes: 220
Averiguar versión de ADO
« en: Abril 13, 2012, 11:05:05 pm »
Palabras clave: ADO, versión, librería, referencia, msado
Autor: Rubén Vigón
Extraído de: La web del Búho

Objetivo:
Averiguar la versión del archivo "msado15.dll

Código: [Seleccionar]
' ***********************************************************
' Versión ADO - Devuelve la versión del archivo "msado15.dll"
' Rubén Vigón - vigon@wanadoo.es
' ***********************************************************

Option Explicit
Private Type VS_FIXEDFILEINFO
   dwSignature As Long
   dwStrucVersionl As Integer
   dwStrucVersionh As Integer
   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 Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, ByVal Source As Long, ByVal length As Long)
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 Function SHGetValue Lib "SHLWAPI.DLL" Alias "SHGetValueA" (ByVal HKEY As Long, ByVal pszSubKey As String, ByVal pszValue As String, pdwType As Long, pvData As Any, pcbData As Long) As Long

Private Function VersionArchivo(ByVal strRuta As String) As String
Dim arrBuffer() As Byte, lngBufferLen As Long
Dim ffiVerBuffer As VS_FIXEDFILEINFO, lngVerPointer As Long
   lngBufferLen = GetFileVersionInfoSize(strRuta, 0)
   If lngBufferLen < 1 Then
      Err.Raise "No se puede acceder a la versión del archivo " & strRuta
   Else
      ReDim sBuffer(lngBufferLen)
      GetFileVersionInfo strRuta, 0&, lngBufferLen, sBuffer(0)
      VerQueryValue sBuffer(0), "\", lngVerPointer, 0
      MoveMemory ffiVerBuffer, lngVerPointer, Len(ffiVerBuffer)
      VersionArchivo = ffiVerBuffer.dwFileVersionMSh & "." & ffiVerBuffer.dwFileVersionMSl & "." & ffiVerBuffer.dwFileVersionLSh & "." & ffiVerBuffer.dwFileVersionLSl
   End If
End Function

Private Function LeerClave(ByVal strRama As String, ByVal strClave As String) As String
Const HKEY_LOCAL_MACHINE As Long = &H80000002, REG_SZ As Long = 1
Dim strResult As String
   strResult = String$(256, vbNullChar)
   If SHGetValue(HKEY_LOCAL_MACHINE, strRama, strClave, REG_SZ, ByVal strResult, Len(strResult)) = 0 Then
      LeerClave = Left$(strResult, InStr(strResult, vbNullChar) - 1)
   Else
      Err.Raise "No se puede acceder a la clave " & strClave & " de la rama " & strRama
   End If
End Function

Private Sub Form_Load()
Dim strRutaArchivosComunes As String
   strRutaArchivosComunes = LeerClave("Software\Microsoft\Windows\CurrentVersion", "CommonFilesDir")
   MsgBox "Versión ADO: " & VersionArchivo(strRutaArchivosComunes & "\System\ado\msado15.dll")
End Sub
« Última modificación: Abril 13, 2012, 11:29:44 pm por xavi »