这是一个简单的函数,你可以使用一个 VersionInfo 数组元素作为参数。<br> Label1.Caption := GetFileInfo('c:/windows/explorer.exe', VersionInfo[3]); <br> or <br> Label1.Caption := GetFileInfo('c:/windows/explorer.exe', 'FileVersion'); <br> <br> <br> =============================================== <br> unit lFilever; <br> interface <br> uses <br> WinTypes, WinProcs, SysUtils {$IFNDEF WIN32} ,Ver {$ENDIF}; <br> const <br> VersionInfo: array [1..8] of string = ( <br> 'CompanyName', 'FileDescription', 'FileVersion', 'InternalName', <br> 'LegalCopyRight', 'OriginalFileName', 'ProductName', 'ProductVersion'); <br> <br> function GetFileInfo(FName, InfoType: string): string; <br> <br> implementation <br> <br> function GetFileInfo(FName, InfoType: string): string; <br> var <br> Info : Pointer; <br> InfoData : Pointer; <br> InfoSize : LongInt; <br> InfoLen : {$IFDEF WIN32} DWORD;{$ELSE} LongInt; {$ENDIF} <br> DataLen : {$IFDEF WIN32} UInt; {$ELSE} word; {$ENDIF} <br> LangPtr : Pointer; <br> begin <br> result:=''; DataLen:=255; <br> if Length(FName)<=0 then exit; <br> FName:=FName+#0; <br> InfoSize:=GetFileVersionInfoSize(@Fname[1], InfoLen); <br> if (InfoSize > 0) then <br> begin <br> GetMem(Info, InfoSize); <br> try <br> if GetFileVersionInfo(@FName[1], InfoLen, InfoSize, Info) then <br> begin <br> if VerQueryValue(Info,'/VarFileInfo/Translation',LangPtr, DataLen) then <br> InfoType:=Format('/StringFileInfo/%0.4x%0.4x/%s'#0,[LoWord(LongInt(LangPtr^)), <br> HiWord(LongInt(LangPtr^)), InfoType]); <br> if VerQueryValue(Info,@InfoType[1],InfoData,Datalen) then <br> Result := strPas(InfoData); <br> end; <br> finally <br> FreeMem(Info, InfoSize); <br> end; <br> end; <br> end; <br> <br> end.<br><br>