« レジストリの書き込み(WSH) | Main | FileSystemObjectフォルダ再帰検索 »

ファイルのバージョン情報を取得

' ファイルのバージョン情報を取得
Option Explicit
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

Type CODEPAGE
lngLOW As Integer
lngHIGH As Integer
End Type

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)

Function GetFileVer(exename As String) As String

'"Comments"'コメント
'"CompanyName"'社名
'"FileDescription"'説明
'"FileVersion"'ファイルバージョン
'"InternalName"'内部名
'"LegalCopyright"'著作権
'"LegalTrademarks"'商標
'"OriginalFilename"'正式ファイル名
'"PrivateBuild"'プライベートビルド情報
'"ProductName"'製品名
'"ProductVersion"'製品バージョン
'"SpecialBuild"'スペシャルビルド情報

Dim lngRet As Long
Dim lngDummy As Long
Dim bBuffer() As Byte
Dim lngLen As Long
Dim lpbuffer As Long
Dim ffi As VS_FIXEDFILEINFO
Dim strFileName As String
GetFileVer = ""
' strFileName に取得したいファイル名をセット
strFileName = exename

' サイズを取得
lngLen = GetFileVersionInfoSize(strFileName, lngDummy)
If lngLen < 1 Then
Exit Function
End If

' バイトの配列の領域取得
ReDim bBuffer(lngLen)

' ファイル バージョン情報を取得
lngRet = GetFileVersionInfo(strFileName, 0&, lngLen, bBuffer(0))
lngRet = VerQueryValue(bBuffer(0), "\", lpbuffer, lngLen)

' バイトの処理
MoveMemory ffi, lpbuffer, Len(ffi)

' ファイル バージョン
GetFileVer = _
Format$(ffi.dwFileVersionMSh) & "." & _
Format$(ffi.dwFileVersionMSl) & _
Format$(ffi.dwFileVersionLSh) & "." & _
Format$(ffi.dwFileVersionLSl, "0000")

' ' 製品バージョン
' Debug.Print "ProductVersion = " & _
' Format$(ffi.dwProductVersionMSh) & "." & _
' Format$(ffi.dwProductVersionMSl) & "." & _
' Format$(ffi.dwProductVersionLSh) & "." & _
' Format$(ffi.dwProductVersionLSl)

End Function

|

« レジストリの書き込み(WSH) | Main | FileSystemObjectフォルダ再帰検索 »

Comments

Post a comment



(Not displayed with comment.)




TrackBack

TrackBack URL for this entry:
http://app.cocolog-nifty.com/t/trackback/4099/22591

Listed below are links to weblogs that reference ファイルのバージョン情報を取得:

« レジストリの書き込み(WSH) | Main | FileSystemObjectフォルダ再帰検索 »