Code:
'------------------------------------------------------------------------------ ' Returns version string info from a file. If sItem="", returns version number ' With sincere thanks to Egbert Zijlema for working it all out! ' ' Updated 17th September 2002 - Fully tested OK with WinME and NT 4.0. '------------------------------------------------------------------------------ Function GetVersionInfo(ByVal sFile As String, ByVal sItem As String) As String Local pLang As Long Ptr, sLangID As String, fvTail As String, pvTail As String, sBuf As String Local bSize As Long, pValue As Asciiz Ptr, dwDummy As Dword, ffi As VS_FIXEDFILEINFO Ptr ' Obtain the version block bSize = GetFileVersionInfoSize(ByCopy sFile, dwDummy) If IsFalse bSize Then Exit Function sBuf = Space$(bSize) If IsFalse GetFileVersionInfo(ByCopy sFile, 0, bSize, ByVal StrPtr(sBuf)) Then Exit Function ' If string item was specified, attempt to obtain it If Len(sItem) Then ' Check language id - default to American English if not found If IsFalse VerQueryValue(ByVal StrPtr(sBuf), "\VarFileInfo\Translation", pLang, dwDummy) Then sLangID = "040904E4" ' American English/ANSI Else sLangID = Hex$(LoWrd(@pLang), 4) + Hex$(HiWrd(@pLang), 4) End If ' Get the string information from the resource and return it If VerQueryValue(ByVal StrPtr(sBuf), "\StringFileInfo\" + sLangID + "\" + sItem, pValue, dwDummy) Then Function = @pValue Else ' Otherwise, query the numeric version value If VerQueryValue(ByVal StrPtr(sBuf), "\", ByVal VarPtr(ffi), dwDummy) Then fvTail = Format$(LoWrd(@ffi.dwFileVersionLS), "00") pvTail = Format$(LoWrd(@ffi.dwProductVersionLS), "00") If HiWrd(@ffi.dwFileversionLS) Then fvTail = Format$(HiWrd(@ffi.dwFileVersionLS), "00") + fvTail If HiWrd(@ffi.dwProductVersionLS) Then pvTail = Format$(HiWrd(@ffi.dwProductVersionLS), "00") + pvTail Function = Format$(HiWrd(@ffi.dwFileVersionMS)) + "." + Format$(LoWrd(@ffi.dwFileVersionMS), "00") + "." + fvTail End If End If End Function
Kev Peel
KGP Software
Bridgwater, UK.
mailto:[email protected][email protected]</A>
[This message has been edited by K Peel (edited September 17, 2002).]
Comment