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