如何读一个 exe 的版本信息?就是"属性"里的 1.00.00 版之类的那个(50分)

  • 主题发起人 主题发起人 QSmile
  • 开始时间 开始时间
Q

QSmile

Unregistered / Unconfirmed
GUEST, unregistred user!
如何读一个 exe 的版本信息?就是"属性"里的 1.00.00 版之类的那个
 
unit uVersionInfo;<br><br>interface<br><br>uses<br> &nbsp;Windows, SysUtils, Classes;<br><br>type<br> &nbsp;TVersionInfo = record<br> &nbsp; &nbsp;CommpanyName: string;<br> &nbsp; &nbsp;FileDescription: string;<br> &nbsp; &nbsp;FileVersion: string;<br> &nbsp; &nbsp;InternalName: string;<br> &nbsp; &nbsp;LegalCopyright: string;<br> &nbsp; &nbsp;LegalTrademarks: string;<br> &nbsp; &nbsp;OriginalFileName: string;<br> &nbsp; &nbsp;ProductName: string;<br> &nbsp; &nbsp;ProductVersion: string;<br> &nbsp; &nbsp;Comments: string;<br> &nbsp; &nbsp;VsFixedFileInfo:VS_FIXEDFILEINFO;<br> &nbsp; &nbsp;UserDefineValue:string;<br> &nbsp;end;<br><br>function GetFileVersionInfomation(<br> &nbsp; &nbsp;const FileName: string;<br> &nbsp; &nbsp;var &nbsp; info: TVersionInfo;<br> &nbsp; &nbsp;const UserDefine &nbsp;: string=''<br> &nbsp; &nbsp;): boolean;<br><br>implementation<br><br>function GetFileVersionInfomation(<br> &nbsp; &nbsp;const FileName: string;<br> &nbsp; &nbsp;var &nbsp; info: TVersionInfo;<br> &nbsp; &nbsp;const UserDefine &nbsp;: string=''<br> &nbsp; &nbsp;): boolean;<br>const<br> &nbsp;SFInfo= '/StringFileInfo/';<br>var<br> &nbsp;VersionInfo: Pointer;<br> &nbsp;InfoSize: DWORD;<br> &nbsp;InfoPointer: Pointer;<br> &nbsp;Translation: Pointer;<br> &nbsp;VersionValue: string;<br> &nbsp;unused: DWORD;<br>begin<br> &nbsp;unused := 0;<br> &nbsp;Result := False;<br> &nbsp;InfoSize := GetFileVersionInfoSize(pchar(FileName), unused);<br> &nbsp;if InfoSize &gt; 0 then<br> &nbsp;begin<br> &nbsp; &nbsp;GetMem(VersionInfo, InfoSize);<br> &nbsp; &nbsp;Result := GetFileVersionInfo(pchar(FileName), 0, InfoSize, VersionInfo);<br> &nbsp; &nbsp;if Result then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;VerQueryValue(VersionInfo, '/VarFileInfo/Translation', Translation, InfoSize);<br> &nbsp; &nbsp; &nbsp;VersionValue := SFInfo + IntToHex(LoWord(Longint(Translation^)), 4) +<br> &nbsp; &nbsp; &nbsp; &nbsp;IntToHex(HiWord(Longint(Translation^)), 4) + '/';<br> &nbsp; &nbsp; &nbsp;VerQueryValue(VersionInfo, pchar(VersionValue + 'CompanyName'), InfoPointer, InfoSize);<br> &nbsp; &nbsp; &nbsp;info.CommpanyName := string(pchar(InfoPointer));<br> &nbsp; &nbsp; &nbsp;VerQueryValue(VersionInfo, pchar(VersionValue + 'FileDescription'), InfoPointer, InfoSize);<br> &nbsp; &nbsp; &nbsp;info.FileDescription := string(pchar(InfoPointer));<br> &nbsp; &nbsp; &nbsp;VerQueryValue(VersionInfo, pchar(VersionValue + 'FileVersion'), InfoPointer, InfoSize);<br> &nbsp; &nbsp; &nbsp;info.FileVersion := string(pchar(InfoPointer));<br> &nbsp; &nbsp; &nbsp;VerQueryValue(VersionInfo, pchar(VersionValue + 'InternalName'), InfoPointer, InfoSize);<br> &nbsp; &nbsp; &nbsp;info.InternalName := string(pchar(InfoPointer));<br> &nbsp; &nbsp; &nbsp;VerQueryValue(VersionInfo, pchar(VersionValue + 'LegalCopyright'), InfoPointer, InfoSize);<br> &nbsp; &nbsp; &nbsp;info.LegalCopyright := string(pchar(InfoPointer));<br> &nbsp; &nbsp; &nbsp;VerQueryValue(VersionInfo, pchar(VersionValue + 'LegalTrademarks'), InfoPointer, InfoSize);<br> &nbsp; &nbsp; &nbsp;info.LegalTrademarks := string(pchar(InfoPointer));<br> &nbsp; &nbsp; &nbsp;VerQueryValue(VersionInfo, pchar(VersionValue + 'OriginalFileName'), InfoPointer, InfoSize);<br> &nbsp; &nbsp; &nbsp;info.OriginalFileName := string(pchar(InfoPointer));<br> &nbsp; &nbsp; &nbsp;VerQueryValue(VersionInfo, pchar(VersionValue + 'ProductName'), InfoPointer, InfoSize);<br> &nbsp; &nbsp; &nbsp;info.ProductName := string(pchar(InfoPointer));<br> &nbsp; &nbsp; &nbsp;VerQueryValue(VersionInfo, pchar(VersionValue + 'ProductVersion'), InfoPointer, InfoSize);<br> &nbsp; &nbsp; &nbsp;info.ProductVersion := string(pchar(InfoPointer));<br> &nbsp; &nbsp; &nbsp;VerQueryValue(VersionInfo, pchar(VersionValue + 'Comments'), InfoPointer, InfoSize);<br> &nbsp; &nbsp; &nbsp;info.Comments := string(pchar(InfoPointer));<br> &nbsp; &nbsp; &nbsp;if VerQueryValue(VersionInfo, '/', InfoPointer, InfoSize) then<br> &nbsp; &nbsp; &nbsp; &nbsp;info.VsFixedFileInfo := TVSFixedFileInfo(InfoPointer^);<br> &nbsp; &nbsp; &nbsp;if UserDefine&lt;&gt;'' then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;if VerQueryValue(VersionInfo,pchar(VersionValue+UserDefine),InfoPointer,InfoSize) then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;info.UserDefineValue:=string(pchar(InfoPointer));<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;FreeMem(VersionInfo);<br> &nbsp;end;<br>end;<br><br>end.
 
上面程序我用过,在获取winrar主程序版本信息时会出现错误
 
还_有_没_有_好点的?
 
是不是这个啊<br><br><br>//给你一个我一年多以前写的一个程序.功能比仅仅得到版本多很多.你看一下,然后把<br>//没用的东西删掉就可以了,不过后来一直没去做完善,可能有一些BUG,如果你有兴趣的话,<br>//改好了,别忘了给我一份,呵呵.<br>//TFileInformation获得关于(dll,exe,vxd等文件的信息)<br>//<br>{<br> &nbsp;<br><br>来自:alter, 时间:2001-11-5 17:50:00, ID:708496<br>本来还可以取出其他的信息,比如版权申明之类的,没有用到,就把他删掉了<br>但版本和Build都有<br>var<br> &nbsp; &nbsp;dwHandle,dwLen,puLen : Cardinal;<br> &nbsp; &nbsp;lpData &nbsp;: Array[0..1023] of Char;<br> &nbsp; &nbsp;tmpInfo : PChar;<br> &nbsp; &nbsp;lpSubBlock : string;<br> &nbsp; &nbsp;lplpPointer : Pointer;<br> &nbsp; &nbsp;Lang : Dword;<br>begin<br> &nbsp;tmpInfo := StrAlloc(256);<br><br> &nbsp;dwLen := GetFileVersionInfoSize(Pchar(Application.ExeName),dwHandle);<br> &nbsp;if dwLen = 0 then exit;<br><br> &nbsp;if not GetFileVersionInfo(Pchar(Application.ExeName),dwHandle,dwLen,@lpData) then<br> &nbsp; &nbsp;exit;<br><br> &nbsp;lpSubBlock := '/VarFileInfo/Translation';<br> &nbsp;if VerQueryValue(@lpData,PChar(lpSubBlock),lplpPointer,puLen) then<br> &nbsp;begin<br> &nbsp; &nbsp; Lang := DWORD(lplpPointer^);<br><br> &nbsp; &nbsp;//取得版本号<br> &nbsp; &nbsp;lpSubBlock := Format('/StringFileInfo/%.04X%.04X/FileVersion',<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[LoWord(Lang),HiWord(Lang)]);<br> &nbsp; &nbsp;if VerQueryValue(@lpData,PChar(lpSubBlock),lplpPointer,puLen) then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;StrCopy(tmpInfo,lplpPointer);<br> &nbsp; &nbsp; &nbsp; &nbsp;Label2.Caption:= '版本 '+StrPas(tmpInfo);<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp;end;<br> &nbsp;StrDispose(tmpInfo);<br>end; &nbsp;<br><br> &nbsp;}<br>{**********************************************************************}<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{ &nbsp; &nbsp; &nbsp; File Information Component &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{ &nbsp; &nbsp; &nbsp; &nbsp;version 1.0 for Delphi 5 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{ &nbsp; &nbsp; &nbsp; Copyright (C) 2001 Sun Yu &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{**********************************************************************}<br>{ &nbsp;This Component include TFileInformation. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{ &nbsp;The TFileInformation is object to user. It's used to get the &nbsp; &nbsp; &nbsp; &nbsp;}<br>{ &nbsp;file(mainly *.dll,*.exe,*.vxd) version information, the operation &nbsp; }<br>{ &nbsp;system on which the file run and the file type(e.g. app, dll,drv) &nbsp; }<br>{ &nbsp;Main function and Constant Listed as follows : &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{ &nbsp;LanguageName &nbsp; &nbsp; &nbsp; : the language which file complied with &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{ &nbsp;CompanyName &nbsp; &nbsp; &nbsp; &nbsp;: the file's company name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{ &nbsp;FileVersion &nbsp; &nbsp; &nbsp; &nbsp;: the file version &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{ &nbsp;ProductVersion &nbsp; &nbsp; : the product version &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{ &nbsp;ProductName &nbsp; &nbsp; &nbsp; &nbsp;: the product name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{ &nbsp;InternalName &nbsp; &nbsp; &nbsp; : the file's internal name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{ &nbsp;OriginalFileName &nbsp; : the file's original file name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{ &nbsp;LegalCopyright &nbsp; &nbsp; : the legal copyright &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{ &nbsp;LegalTrademarks &nbsp; &nbsp;: the legal trade marks &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{ &nbsp;FileDescription &nbsp; &nbsp;: the description of file &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>{ &nbsp;Comments &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : the comments of file &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{ &nbsp;PrivateBuild &nbsp; &nbsp; &nbsp; : the private build number &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{ &nbsp;SpecialBuild &nbsp; &nbsp; &nbsp; : the special build number &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{ &nbsp;FileType &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : the file type with chinese or english format &nbsp; }<br>{ &nbsp;FileOSType &nbsp; &nbsp; &nbsp; &nbsp; : the platform on which file run with chinese or }<br>{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; english format &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>{**********************************************************************}<br><br><br>unit FileInformation;<br><br>interface<br><br>uses windows, classes, sysutils;<br><br>Type TFileInfo = record<br> &nbsp;ID : DWORD;<br> &nbsp;CNName : string;<br> &nbsp;ENName : string;<br>end;<br><br>Type<br> &nbsp;TFileInformation = class(TObject)<br> &nbsp;private<br> &nbsp; &nbsp;FFileName : string;<br> &nbsp; &nbsp;lpData : PChar;<br> &nbsp; &nbsp;FResult : boolean;<br> &nbsp; &nbsp;FLangID : WORD;<br> &nbsp; &nbsp;FLangSubID &nbsp;: WORD;<br> &nbsp; &nbsp;FFixFileInfo : PVSFixedFileInfo;<br> &nbsp; &nbsp;FHasVer : boolean;<br> &nbsp;protected<br> &nbsp; &nbsp;LanguageCode : string;<br> &nbsp; &nbsp;Procedure GetLanguageCode;<br> &nbsp; &nbsp;function Indexof(ftype : DWORD; TypeSet : array of TFileInfo) : integer;<br> &nbsp; &nbsp;function HasVersionInfo : boolean;<br> &nbsp;public<br> &nbsp; &nbsp;constructor Create(FileName : string);<br> &nbsp; &nbsp;destructor &nbsp;Destroy; override;<br> &nbsp; &nbsp;function LanguageName : string;<br> &nbsp; &nbsp;function CompanyName : string;<br> &nbsp; &nbsp;function FileVersion : string;<br> &nbsp; &nbsp;function ProductVersion : string;<br> &nbsp; &nbsp;function ProductName : string;<br> &nbsp; &nbsp;function InternalName : string;<br> &nbsp; &nbsp;function OriginalFileName : string;<br> &nbsp; &nbsp;function LegalCopyright : string;<br> &nbsp; &nbsp;function LegalTrademarks : string;<br> &nbsp; &nbsp;function FileDescription : string;<br> &nbsp; &nbsp;function Comments : string;<br> &nbsp; &nbsp;function PrivateBuild : string;<br> &nbsp; &nbsp;function SpecialBuild : string;<br> &nbsp; &nbsp;function FileSize: Integer;<br> &nbsp; &nbsp;function FileType(IsChinese : boolean=True) : string;<br> &nbsp; &nbsp;function FileOSType(IsChinese : boolean=True) : string;<br> &nbsp;end;<br><br>implementation<br><br>const<br> &nbsp;CFileOS : array[1..9] of TFileInfo =<br> &nbsp;((ID: VOS_DOS; &nbsp; &nbsp;CNName: 'MS-DOS程序'; &nbsp; &nbsp;ENName: 'designed for MS-DOS'),<br> &nbsp; (ID: VOS_NT; &nbsp; &nbsp; CNName: 'Windows NT/Windows 2000程序'; &nbsp; &nbsp;ENName: 'designed for Windows NT/Windows 2000'),<br> &nbsp; (ID: VOS__WINDOWS16; &nbsp;CNName: '16-bit Windows程序'; &nbsp; &nbsp;ENName: 'designed for 16-bit Windows'),<br> &nbsp; (ID: VOS__WINDOWS32; &nbsp;CNName: '32-bit Windows程序'; &nbsp; &nbsp;ENName: 'designed for 32-bit Windows API'),<br> &nbsp; (ID: VOS_OS216; &nbsp; &nbsp; &nbsp; CNName: '16-bit OS/2程序'; &nbsp; &nbsp;ENName: 'designed for 16-bit OS/2'),<br> &nbsp; (ID: VOS_OS232; &nbsp; &nbsp;CNName: '32-bit OS/2程序'; &nbsp; &nbsp;ENName: 'designed for 32-bit OS/2'),<br> &nbsp; (ID: VOS__PM16; &nbsp; &nbsp;CNName: '16-bit OS/2 Presentation Manager'; &nbsp; &nbsp;ENName: 'designed for 16-bit Presentation Manager'),<br> &nbsp; (ID: VOS_OS232; &nbsp; &nbsp;CNName: '32-bit OS/2 Presentation Manager'; &nbsp; &nbsp;ENName: 'designed for 32-bit Presentation Manager'),<br> &nbsp; (ID: VOS_UNKNOWN; &nbsp; &nbsp;CNName: '未知平台程序'; &nbsp; &nbsp;ENName: 'designed for unknown Operation system'));<br><br> &nbsp;CFileType : array[1..7] of TFileInfo =<br> &nbsp;((ID: VFT_UNKNOWN; &nbsp; CNName: '未知类型文件'; &nbsp; ENName: 'unknown file type'),<br> &nbsp; (ID: VFT_APP; &nbsp; &nbsp; &nbsp; CNName: '应用程序'; &nbsp; &nbsp; &nbsp; ENName: 'an application'),<br> &nbsp; (ID: VFT_DLL; &nbsp; &nbsp; &nbsp; CNName: '动态链接库(DLL)';ENName: 'dynamic-link library (DLL)'),<br> &nbsp; (ID: VFT_DRV; &nbsp; &nbsp; &nbsp; CNName: '设备驱动文件'; &nbsp; ENName: 'a device driver'),<br> &nbsp; (ID: VFT_FONT; &nbsp; &nbsp; &nbsp;CNName: '字库文件'; &nbsp; &nbsp; &nbsp; ENName: 'a font'),<br> &nbsp; (ID: VFT_VXD; &nbsp; &nbsp; &nbsp; CNName: '虚拟设备文件'; &nbsp; ENName: 'a virtual device'),<br> &nbsp; (ID: VFT_STATIC_LIB;CNName: '静态链接库(LIB)';ENName: 'a static-link library'));<br><br> &nbsp;CFileDriverType : array[1..11] of TFileInfo =<br> &nbsp;((ID: VFT2_UNKNOWN; &nbsp; &nbsp; CNName: '未知类型文件'; ENName: 'unknown driver type'),<br> &nbsp; (ID: VFT2_DRV_COMM; &nbsp; &nbsp;CNName: '通讯驱动文件'; ENName: 'a communications driver'),<br> &nbsp; (ID: VFT2_DRV_PRINTER; CNName: '打印驱动文件'; ENName: 'a printer driver'),<br> &nbsp; (ID: VFT2_DRV_KEYBOARD;CNName: '键盘驱动文件'; ENName: 'a keyboard driver'),<br> &nbsp; (ID: VFT2_DRV_LANGUAGE;CNName: '语言驱动文件'; ENName: 'a language driver'),<br> &nbsp; (ID: VFT2_DRV_DISPLAY; CNName: '显示驱动文件'; ENName: 'a display driver'),<br> &nbsp; (ID: VFT2_DRV_MOUSE; &nbsp; CNName: '鼠标驱动文件'; ENName: 'a mouse driver'),<br> &nbsp; (ID: VFT2_DRV_NETWORK; CNName: '网络驱动文件'; ENName: 'a network driver'),<br> &nbsp; (ID: VFT2_DRV_SYSTEM; &nbsp;CNName: '系统驱动文件'; ENName: 'a system driver'),<br> &nbsp; (ID: VFT2_DRV_INSTALLABLE; CNName: '安装驱动文件'; ENName: 'a installable driver'),<br> &nbsp; (ID: VFT2_DRV_SOUND; &nbsp; CNName: '声音驱动文件'; ENName: 'a sound driver'));<br><br> &nbsp;CFileFontType : array[1..4] of TFileInfo =<br> &nbsp;((ID: VFT2_UNKNOWN; &nbsp; &nbsp; &nbsp;CNName: '未知字库文件'; &nbsp; &nbsp; ENName: 'unknown font type'),<br> &nbsp; (ID: VFT2_FONT_RASTER; &nbsp;CNName: '光栅字库文件'; &nbsp; &nbsp; ENName: 'a raster font'),<br> &nbsp; (ID: VFT2_FONT_VECTOR; &nbsp;CNName: '矢量字库文件'; &nbsp; &nbsp; ENName: 'a vector font'),<br> &nbsp; (ID: VFT2_FONT_TRUETYPE;CNName: 'TRUETYPE字库文件'; ENName: 'a TrueType font'));<br><br>{ TFileVersion }<br><br>// construct TFileVersion Class<br>constructor TFileInformation.Create(FileName : string);<br>var<br> &nbsp;tempHD : cardinal;<br> &nbsp;VerLeng : DWORD;<br> &nbsp;CurLeng : cardinal;<br>begin<br> &nbsp;FResult := False;<br> &nbsp;FFileName := FileName;<br> &nbsp;VerLeng := GetFileVersionInfoSize(PChar(FFileName),tempHD);<br> &nbsp;if VerLeng &lt;&gt; 0 then<br> &nbsp;begin<br> &nbsp; &nbsp;GetMem(lpData,VerLeng);<br> &nbsp; &nbsp;if GetFileVersionInfo(PChar(FFileName),0,VerLeng,lpData) then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;FResult := True;<br> &nbsp; &nbsp; &nbsp;VerQueryValue(lpData,'/',Pointer(FFixFileInfo),CurLeng);<br> &nbsp; &nbsp; &nbsp;FHasVer := HasVersionInfo;<br> &nbsp; &nbsp; &nbsp;GetLanguageCode;<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br>end;<br><br>// destruct TFileInformation Class<br>destructor TFileInformation.Destroy;<br>begin<br> &nbsp;inherited;<br> &nbsp;if FResult then FreeMem(lpData);<br>end;<br><br><br>// get language code<br>procedure TFileInformation.GetLanguageCode;<br>var<br> &nbsp;lpBuf : pLongInt;<br> &nbsp;VerLeng : cardinal;<br>begin<br> &nbsp;if FResult and FHasVer then<br> &nbsp; &nbsp;if VerQueryValue(lpData,'/VarFileInfo/Translation',Pointer(lpBuf),Verleng) then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;FLangID := LoWord(lpBuf^);<br> &nbsp; &nbsp; &nbsp;FLangSubID := HiWord(lpBuf^);<br> &nbsp; &nbsp; &nbsp;LanguageCode := IntToHex(FLangID,4)+IntToHex(FLangSubID,4);<br> &nbsp; &nbsp;end;<br>end;<br><br>// get language name<br>function TFileInformation.LanguageName: string;<br>var<br> &nbsp;Lang : TLanguages;<br>begin<br> &nbsp;if FResult then<br> &nbsp;begin<br> &nbsp; &nbsp;Lang := TLanguages.Create;<br> &nbsp; &nbsp;result := Lang.Name[Lang.Indexof(FLangID)];<br> &nbsp; &nbsp;Lang.Free;<br> &nbsp;end;<br>end;<br><br>// get company name<br>function TFileInformation.CompanyName: string;<br>var<br> &nbsp;lpBuf : PChar;<br> &nbsp;VerLeng : cardinal;<br>begin<br> &nbsp;if FResult and FHasVer then<br> &nbsp; &nbsp;if VerQueryValue(lpData,PChar('/StringFileInfo/'+LanguageCode+'/CompanyName/'),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Pointer(lpBuf),VerLeng) then<br> &nbsp; &nbsp; &nbsp;result := lpBuf;<br>end;<br><br>// get file version<br>function TFileInformation.FileVersion: string;<br>var<br> &nbsp;lpBuf : PChar;<br> &nbsp;VerLeng : cardinal;<br>begin<br> &nbsp;if FResult and FHasVer then<br> &nbsp; &nbsp;if VerQueryValue(lpData,PChar('/StringFileInfo/'+LanguageCode+'/FileVersion/'),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Pointer(lpBuf),VerLeng) then<br> &nbsp; &nbsp; &nbsp;result := lpBuf;<br>end;<br><br>// get product version<br>function TFileInformation.ProductVersion: string;<br>var<br> &nbsp;lpBuf : PChar;<br> &nbsp;VerLeng : cardinal;<br>begin<br> &nbsp;if FResult and FHasVer then<br> &nbsp; &nbsp;if VerQueryValue(lpData,PChar('/StringFileInfo/'+LanguageCode+'/ProductVersion/'),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Pointer(lpBuf),VerLeng) then<br> &nbsp; &nbsp; &nbsp;result := lpBuf;<br>end;<br><br>// get product name<br>function TFileInformation.ProductName: string;<br>var<br> &nbsp;lpBuf : PChar;<br> &nbsp;VerLeng : cardinal;<br>begin<br> &nbsp;if FResult and FHasVer then<br> &nbsp; &nbsp;if VerQueryValue(lpData,PChar('/StringFileInfo/'+LanguageCode+'/ProductName/'),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Pointer(lpBuf),VerLeng) then<br> &nbsp; &nbsp; &nbsp;result := lpBuf;<br>end;<br><br>// get internal name<br>function TFileInformation.InternalName: string;<br>var<br> &nbsp;lpBuf : PChar;<br> &nbsp;VerLeng : cardinal;<br>begin<br> &nbsp;if FResult and FHasVer then<br> &nbsp; &nbsp;if VerQueryValue(lpData,PChar('/StringFileInfo/'+LanguageCode+'/InternalName/'),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Pointer(lpBuf),VerLeng) then<br> &nbsp; &nbsp; &nbsp;result := lpBuf;<br>end;<br><br>// get original file name<br>function TFileInformation.OriginalFileName: string;<br>var<br> &nbsp;lpBuf : PChar;<br> &nbsp;VerLeng : cardinal;<br>begin<br> &nbsp;if FResult and FHasVer then<br> &nbsp; &nbsp;if VerQueryValue(lpData,PChar('/StringFileInfo/'+LanguageCode+'/OriginalFileName/'),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Pointer(lpBuf),VerLeng) then<br> &nbsp; &nbsp; &nbsp;result := lpBuf;<br>end;<br><br>// get legal copyright<br>function TFileInformation.LegalCopyright: string;<br>var<br> &nbsp;lpBuf : PChar;<br> &nbsp;VerLeng : cardinal;<br>begin<br> &nbsp;if FResult and FHasVer then<br> &nbsp; &nbsp;if VerQueryValue(lpData,PChar('/StringFileInfo/'+LanguageCode+'/LegalCopyright/'),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Pointer(lpBuf),VerLeng) then<br> &nbsp; &nbsp; &nbsp;result := lpBuf;<br>end;<br><br>// get legal trademarks<br>function TFileInformation.LegalTrademarks: string;<br>var<br> &nbsp;lpBuf : PChar;<br> &nbsp;VerLeng : cardinal;<br>begin<br> &nbsp;if FResult and FHasVer then<br> &nbsp; &nbsp;if VerQueryValue(lpData,PChar('/StringFileInfo/'+LanguageCode+'/LegalTrademarks/'),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Pointer(lpBuf),VerLeng) then<br> &nbsp; &nbsp; &nbsp;result := lpBuf;<br>end;<br><br>// get file description<br>function TFileInformation.FileDescription: string;<br>var<br> &nbsp;lpBuf : PChar;<br> &nbsp;VerLeng : cardinal;<br>begin<br> &nbsp;if FResult and FHasVer then<br> &nbsp; &nbsp;if VerQueryValue(lpData,PChar('/StringFileInfo/'+LanguageCode+'/FileDescription/'),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Pointer(lpBuf),VerLeng) then<br> &nbsp; &nbsp; &nbsp;result := lpBuf;<br>end;<br><br>// get comments<br>function TFileInformation.Comments: string;<br>var<br> &nbsp;lpBuf : PChar;<br> &nbsp;VerLeng : cardinal;<br>begin<br> &nbsp;if FResult and FHasVer then<br> &nbsp; &nbsp;if VerQueryValue(lpData,PChar('/StringFileInfo/'+LanguageCode+'/Comments/'),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Pointer(lpBuf),VerLeng) then<br> &nbsp; &nbsp; &nbsp;result := lpBuf;<br>end;<br><br>// get file private build<br>function TFileInformation.PrivateBuild: string;<br>var<br> &nbsp;lpBuf : PChar;<br> &nbsp;VerLeng : cardinal;<br>begin<br> &nbsp;if FResult and FHasVer then<br> &nbsp; &nbsp;if FFixFileInfo.dwFileFlags = VS_FF_PRIVATEBUILD then<br> &nbsp; &nbsp; &nbsp;if VerQueryValue(lpData,PChar('/StringFileInfo/'+LanguageCode+'/PrivateBuild/'),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Pointer(lpBuf),VerLeng) then<br> &nbsp; &nbsp; &nbsp; &nbsp;result := lpBuf<br> &nbsp;else<br> &nbsp; &nbsp;result := '';<br>end;<br><br>// get file special build<br>function TFileInformation.SpecialBuild: string;<br>var<br> &nbsp;lpBuf : PChar;<br> &nbsp;VerLeng : cardinal;<br>begin<br> &nbsp;if FResult and FHasVer then<br> &nbsp; &nbsp;if FFixFileInfo.dwFileFlags = VS_FF_SPECIALBUILD then<br> &nbsp; &nbsp; &nbsp;if VerQueryValue(lpData,PChar('/StringFileInfo/'+LanguageCode+'/PrivateBuild/'),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Pointer(lpBuf),VerLeng) then<br> &nbsp; &nbsp; &nbsp; &nbsp;result := lpBuf<br> &nbsp;else<br> &nbsp; &nbsp;result := '';<br>end;<br><br>// get file type<br>function TFileInformation.FileType(IsChinese : boolean) : string;<br>var<br> &nbsp;IndexType : integer;<br> &nbsp;IndexSubType : integer;<br>begin<br> &nbsp;if FResult then<br> &nbsp;begin<br> &nbsp; &nbsp;IndexType := Indexof(FFixFileInfo.dwFileType,CFileType);<br> &nbsp; &nbsp;if IndexType &gt; 0 then<br> &nbsp; &nbsp; &nbsp;if FFixFileInfo.dwFileType = VFT_DRV then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;IndexSubType := Indexof(FFixFileInfo.dwFileSubtype,CFileDriverType);<br> &nbsp; &nbsp; &nbsp; &nbsp;if IndexSubType &gt; 0 then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if IsChinese then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result := CFileDriverType[IndexSubType].CNName<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result := CFileDriverType[IndexSubType].ENName<br> &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if IsChinese then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result := CFileType[IndexType].CNName<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result := CFileType[IndexType].ENName<br> &nbsp; &nbsp; &nbsp;end<br> &nbsp; &nbsp; &nbsp;else if FFixFileInfo.dwFileType = VFT_FONT then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;IndexSubType := Indexof(FFixFileInfo.dwFileSubtype,CFileFontType);<br> &nbsp; &nbsp; &nbsp; &nbsp;if IndexSubType &gt; 0 then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if IsChinese then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result := CFileFontType[IndexSubType].CNName<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result := CFileFontType[IndexSubType].ENName<br> &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if IsChinese then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result := CFileType[IndexType].CNName<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result := CFileType[IndexType].ENName<br> &nbsp; &nbsp; &nbsp;end<br> &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp;if IsChinese then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result := CFileType[IndexType].CNName<br> &nbsp; &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;result := CFileType[IndexType].ENName<br> &nbsp; &nbsp; &nbsp;end<br> &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp;result := '';<br>end;<br><br>// get file operation system<br>function TFileInformation.FileOSType(IsChinese : boolean) : string;<br>var<br> &nbsp;Index : integer;<br>begin<br> &nbsp;if FResult then<br> &nbsp;begin<br> &nbsp; &nbsp;Index := Indexof(FFixFileInfo.dwFileOS,CFileOS);<br> &nbsp; &nbsp;if Index &gt; 0 then<br> &nbsp; &nbsp; &nbsp;if IsChinese then<br> &nbsp; &nbsp; &nbsp; &nbsp;result := CFileOS[Index].CNName<br> &nbsp; &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp; &nbsp;result := CFileOS[Index].ENName<br> &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp;result := '';<br> &nbsp;end;<br>end;<br><br>// get the index of file type<br>function TFileInformation.Indexof(ftype : DWORD; TypeSet : array of TFileInfo) : integer;<br>var<br> &nbsp;i : integer;<br>begin<br> &nbsp;result := -1;<br> &nbsp;for i:=Low(TypeSet) to High(TypeSet) do<br> &nbsp; &nbsp;if ftype = TypeSet.ID then<br> &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp;result := i+1;<br> &nbsp; &nbsp; &nbsp;exit;<br> &nbsp; &nbsp;end;<br>end;<br><br>// decide whether the file has version information<br>function TFileInformation.HasVersionInfo : boolean;<br>var<br> &nbsp;ftype : DWORD;<br>begin<br> &nbsp;ftype := FFixFileInfo.dwFileType;<br> &nbsp;if (ftype = VFT_APP) or (ftype = VFT_DLL) or (ftype = VFT_VXD)<br> &nbsp; &nbsp; &nbsp;or (ftype = VFT_STATIC_LIB) then<br> &nbsp; &nbsp;result := True<br> &nbsp;else<br> &nbsp; &nbsp;result := False;<br>end;<br><br>function TFileInformation.FileSize: Integer;<br>var<br> &nbsp;hFile: THandle;<br> &nbsp;Win32FindData: TWin32FindData;<br>begin<br> &nbsp;hFile := FindFirstFile(PChar(FFileName), Win32FindData);<br> &nbsp;if hFile &lt;&gt; INVALID_HANDLE_VALUE then<br> &nbsp;begin<br> &nbsp; &nbsp;Result := Win32FindData.nFileSizeLow;<br> &nbsp; &nbsp;Windows.FindClose(hFile);<br> &nbsp;end<br> &nbsp;else<br> &nbsp; &nbsp;Result := 0;<br>end;<br><br>end.
 
后退
顶部