Kyle_Katarn | Voilà le code VB :
Code :
- Usage
- x = GetVersionInfo("c:\program files\microsoft office\office\MSO9.DLL" )Code
- 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
|
|