Extracts and returns a single or multiple strings of version information from an executable file.
AHK's FileGetVersion command will fetch you the FileVersion, but there are more - that this function would fetch.
Following are Windows Standard Names:
[*:1giapuu9]Comments
[*:1giapuu9]CompanyName
[*:1giapuu9]FileDescription
[*:1giapuu9]FileVersion
[*:1giapuu9]InternalName
[*:1giapuu9]LegalCopyright
[*:1giapuu9]LegalTrademarks
[*:1giapuu9]OriginalFilename
[*:1giapuu9]PrivateBuild
[*:1giapuu9]ProductName
[*:1giapuu9]ProductVersion
[*:1giapuu9]SpecialBuild
Credit : [::script::GetFullVersionInfo] string version info for execs by wOxxOm
Reference : How to extract version information using the Windows API Peter D Johnson
VersionInfo of AutoHotkey_L as seen from ResHacker
Function along with example calls:
FileGetVersionInfo_AW( peFile="", StringFileInfo="", Delimiter="|") { ; Written by SKAN ; www.autohotkey.com/forum/viewtopic.php?t=64128 CD:24-Nov-2008 / LM:28-May-2010 Static CS, HexVal, Sps=" ", DLL="Version\" If ( CS = "" ) CS := A_IsUnicode ? "W" : "A", HexVal := "msvcrt\s" (A_IsUnicode ? "w": "" ) "printf" If ! FSz := DllCall( DLL "GetFileVersionInfoSize" CS , Str,peFile, UInt,0 ) Return "", DllCall( "SetLastError", UInt,1 ) VarSetCapacity( FVI, FSz, 0 ), VarSetCapacity( Trans,8 * ( A_IsUnicode ? 2 : 1 ) ) DllCall( DLL "GetFileVersionInfo" CS, Str,peFile, Int,0, UInt,FSz, UInt,&FVI ) If ! DllCall( DLL "VerQueryValue" CS , UInt,&FVI, Str,"\VarFileInfo\Translation", UIntP,Translation, UInt,0 ) Return "", DllCall( "SetLastError", UInt,2 ) If ! DllCall( HexVal, Str,Trans, Str,"%08X", UInt,NumGet(Translation+0) ) Return "", DllCall( "SetLastError", UInt,3 ) Loop, Parse, StringFileInfo, %Delimiter% { subBlock := "\StringFileInfo\" SubStr(Trans,-3) SubStr(Trans,1,4) "\" A_LoopField If ! DllCall( DLL "VerQueryValue" CS, UInt,&FVI, Str,SubBlock, UIntP,InfoPtr, UInt,0 ) Continue Value := DllCall( "MulDiv", UInt,InfoPtr, Int,1, Int,1, "Str" ) Info .= Value ? ( ( InStr( StringFileInfo,Delimiter ) ? SubStr( A_LoopField Sps,1,24 ) . A_Tab : "" ) . Value . Delimiter ) : "" } StringTrimRight, Info, Info, 1 Return Info } #SingleInstance, Force SetBatchLines -1 Loop, %A_WinDir%\System32\*.??l Files .= "`n" A_LoopFileLongPath Files := A_AhkPath . Files StringFileInfo= ( LTrim [color=#800000] FileDescription FileVersion InternalName LegalCopyright OriginalFilename ProductName ProductVersion CompanyName PrivateBuild SpecialBuild LegalTrademarks [/color]) Loop, Parse, Files, "`n" If VI := FileGetVersionInfo_AW( A_LoopField, StringFileInfo, "`n" ) MsgBox, 64, %A_LoopField%, %VI%
Code Update:
Edit: 28-May-2011
[*:1giapuu9]When a single item is requested, the function returns the value directly instead of a table row. Thanks to HotKeyIt for the suggestion.
[*:1giapuu9]StrGet() has been removed. MulDiv() retrieves text properly in both ( ansi/unicode ) versions properly.