Tipp 0133 Versions-Informationen auslesen
Autor/Einsender:
Datum:
  Detlev Schubert
14.10.2001
Entwicklungsumgebung:   VB 6
Vor allem für Updates und/oder Installationen von neuen Programm-Komponenten ist es wichtig zu erfahren, welche Version denn die z.B. vorhandene Programmdatei hat. Mit Hilfe der API-Funktion GetFileVersionInfo und der zu den einzelnen Betriebssystemen gehörenden Datei Version.dll ist dies auch mit VB möglich.
Die Versions-Informationen können jedoch nur aus Dateien gelesen werden, die auch eine Versions-Information zur Verfügung stellen, wie z.B. *.exe, *.dll, *.ocx, *.vbx, *.drv und *.fon-Dateien.
Code im Codebereich des Moduls
 
Option Explicit

Public StrucVer As String
Public ProdVer As String
Public FileFlags As String
Public FileOS As String
Public FileType As String
Public FileSubType As String

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

Public Const VS_FFI_SIGNATURE = &HFEEF04BD
Public Const VS_FFI_STRUCVERSION = &H10000
Public Const VS_FFI_FILEFLAGSMASK = &H3F&

Public Const VS_FF_DEBUG = &H1
Public Const VS_FF_PRERELEASE = &H2
Public Const VS_FF_PATCHED = &H4
Public Const VS_FF_PRIVATEBUILD = &H8
Public Const VS_FF_INFOINFERRED = &H10
Public Const VS_FF_SPECIALBUILD = &H20

Public Const VOS_UNKNOWN = &H0
Public Const VOS_DOS = &H10000
Public Const VOS_OS216 = &H20000
Public Const VOS_OS232 = &H30000
Public Const VOS_NT = &H40000

Public Const VOS__BASE = &H0
Public Const VOS__WINDOWS16 = &H1
Public Const VOS__PM16 = &H2
Public Const VOS__PM32 = &H3
Public Const VOS__WINDOWS32 = &H4

Public Const VOS_DOS_WINDOWS16 = &H10001
Public Const VOS_DOS_WINDOWS32 = &H10004
Public Const VOS_OS216_PM16 = &H20002
Public Const VOS_OS232_PM32 = &H30003
Public Const VOS_NT_WINDOWS32 = &H40004

Public Const VFT_UNKNOWN = &H0
Public Const VFT_APP = &H1
Public Const VFT_DLL = &H2
Public Const VFT_DRV = &H3
Public Const VFT_FONT = &H4
Public Const VFT_VXD = &H5
Public Const VFT_STATIC_LIB = &H7

Public Const VFT2_UNKNOWN = &H0
Public Const VFT2_DRV_PRINTER = &H1
Public Const VFT2_DRV_KEYBOARD = &H2
Public Const VFT2_DRV_LANGUAGE = &H3
Public Const VFT2_DRV_DISPLAY = &H4
Public Const VFT2_DRV_MOUSE = &H5
Public Const VFT2_DRV_NETWORK = &H6
Public Const VFT2_DRV_SYSTEM = &H7
Public Const VFT2_DRV_INSTALLABLE = &H8
Public Const VFT2_DRV_SOUND = &H9
Public Const VFT2_DRV_COMM = &HA

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

Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias _
    "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, _
    lpdwHandle As Long) As Long

Declare Function VerQueryValue Lib "Version.dll" Alias _
    "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, _
    lplpBuffer As Any, puLen As Long) As Long

Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (dest As Any, ByVal Source As Long, ByVal length As Long)

Declare Function GetSystemDirectory Lib "kernel32" Alias _
    "GetSystemDirectoryA" (ByVal Path As String, ByVal cbBytes _
    As Long) As Long
 
Code im Codebereich der Form
 
Option Explicit

Private Sub Form_Load()
  Drive1.Drive = "c:"
  Dir1 = "Windows"
End Sub

Private Sub Drive1_Change()
  Dir1.Path = Drive1.Drive
End Sub

Private Sub Dir1_Change()
  File1.Path = Dir1.Path
End Sub

Private Sub File1_Click()
  Label2.Caption = " " & FileVer(File1.Path & "\" & File1.FileName)
End Sub

Public Function FileVer(FullFileName As String) As String
  Dim rc                As Long
  Dim lDummy            As Long
  Dim sBuffer()         As Byte
  Dim lBufferLen        As Long
  Dim lVerPointer       As Long
  Dim udtVerBuffer      As VS_FIXEDFILEINFO
  Dim lVerbufferLen     As Long

  lBufferLen = GetFileVersionInfoSize(FullFileName, lDummy)
  If lBufferLen < 1 Then
     FileVer = "Keine Information"
     Exit Function
  End If

  ReDim sBuffer(lBufferLen)
  rc = GetFileVersionInfo(FullFileName, 0&, lBufferLen, sBuffer(0))
  rc = VerQueryValue(sBuffer(0), "\", lVerPointer, lVerbufferLen)
  MoveMemory udtVerBuffer, lVerPointer, Len(udtVerBuffer)

  FileVer = Format$(udtVerBuffer.dwFileVersionMSh) & "." & _
      Format$(udtVerBuffer.dwFileVersionMSl) & "." & _
      Format$(udtVerBuffer.dwFileVersionLSl)
End Function
 
Weitere Links zum Thema
Datei-Eigenschaften ermitteln (FSO)

Windows-Version
95
98/SE
ME
NT
2000
XP
Vista
Win 7
VB-Version
VBA 5
VBA 6
VB 4/16
VB 4/32
VB 5
VB 6


Download  (3,7 kB) Downloads bisher: [ 1738 ]

Vorheriger Tipp Zum Seitenanfang Nächster Tipp

Startseite | Projekte | Tutorials | API-Referenz | VB-/VBA-Tipps | Komponenten | Bücherecke | VB/VBA-Forum | VB.Net-Forum | DirectX-Forum | Foren-Archiv | DirectX | VB.Net-Tipps | Chat | Spielplatz | Links | Suchen | Stichwortverzeichnis | Feedback | Impressum

Seite empfehlen Bug-Report
Letzte Aktualisierung: Dienstag, 9. August 2011