如果读出EXE文件的版本信息其他相关信息!!(100分)

  • 主题发起人 主题发起人 duducat
  • 开始时间 开始时间
D

duducat

Unregistered / Unconfirmed
GUEST, unregistred user!
高手快快!!
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=888865<br><br>来自:wjiachun, 时间:2002-1-28 9:24:00, ID:889146 | 编辑 <br>来自:cAkk 时间:1999-10-5 15:09:09 ID:139642 <br>下面的函数可以得到文件的版本信息,注意,delphi做的程序,如果想<br>包含版本信息, 必须在菜单"project/options/version info"里面<br>添加版本信息.<br>function GetVersion;<br>var<br>&nbsp; InfoSize, Wnd: DWORD;<br>&nbsp; VerBuf: Pointer;<br>&nbsp; szName: array[0..255] of Char;<br>&nbsp; Value: Pointer;<br>&nbsp; Len: UINT;<br>&nbsp; TransString:string;<br>begin<br>&nbsp; InfoSize := GetFileVersionInfoSize(PChar(FileName), Wnd);<br>&nbsp; if InfoSize <> 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; GetMem(VerBuf, InfoSize);<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; if GetFileVersionInfo(PChar(FileName), Wnd, InfoSize, VerBuf) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; Value :=nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; VerQueryValue(VerBuf, '/VarFileInfo/Translation', Value, Len);<br>&nbsp; &nbsp; &nbsp; &nbsp; if Value <> nil then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TransString := IntToHex(MakeLong(HiWord(Longint(Value^)), LoWord(Longint(Value^))), 8);<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := '';<br>&nbsp; &nbsp; &nbsp; &nbsp; StrPCopy(szName, '/StringFileInfo/'+Transstring+'/FileVersion');<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;^^^^^^^此处换成ProductVersion得到的是"产品版本"<br>&nbsp; &nbsp; &nbsp; &nbsp; if VerQueryValue(VerBuf, szName, Value, Len) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result := StrPas(PChar(Value));<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; FreeMem(VerBuf);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>&nbsp;<br>&nbsp;<br><br>--------------------------------------------------------------------------------<br>来自:cAkk 时间:1999-10-5 15:43:42 ID:139661 <br>更正,函数声明为:<br>function GetVersion(filename:string):string;<br><br>忘了加参数了. :-)<br><br>&nbsp;<br>&nbsp;<br><br><br>&nbsp;<br>
 
好东西!我喜欢!
 
&nbsp;这是一个简单的函数,你可以使用一个 VersionInfo 数组元素作为参数。<br>&nbsp; &nbsp; Label1.Caption := GetFileInfo('c:/windows/explorer.exe', VersionInfo[3]); <br>&nbsp; or <br>&nbsp; &nbsp; Label1.Caption := GetFileInfo('c:/windows/explorer.exe', 'FileVersion'); <br>&nbsp; <br>&nbsp; <br>&nbsp; =============================================== <br>&nbsp; unit lFilever; <br>&nbsp; interface <br>&nbsp; uses <br>&nbsp; &nbsp; WinTypes, WinProcs, SysUtils {$IFNDEF WIN32} ,Ver {$ENDIF}; <br>&nbsp; const <br>&nbsp; &nbsp; VersionInfo: array [1..8] of string = ( <br>&nbsp; &nbsp; &nbsp; 'CompanyName', 'FileDescription', 'FileVersion', 'InternalName', <br>&nbsp; &nbsp; &nbsp; 'LegalCopyRight', 'OriginalFileName', 'ProductName', 'ProductVersion'); <br>&nbsp; <br>&nbsp; function GetFileInfo(FName, InfoType: string): string; <br>&nbsp; <br>&nbsp; implementation <br>&nbsp; <br>&nbsp; function GetFileInfo(FName, InfoType: string): string; <br>&nbsp; var <br>&nbsp; &nbsp; Info &nbsp; &nbsp; : Pointer; <br>&nbsp; &nbsp; InfoData : Pointer; <br>&nbsp; &nbsp; InfoSize : LongInt; <br>&nbsp; &nbsp; InfoLen &nbsp;: {$IFDEF WIN32} DWORD;{$ELSE} LongInt; {$ENDIF} <br>&nbsp; &nbsp; DataLen &nbsp;: {$IFDEF WIN32} UInt; {$ELSE} word; {$ENDIF} <br>&nbsp; &nbsp; LangPtr &nbsp;: Pointer; <br>&nbsp; begin <br>&nbsp; &nbsp; result:=''; DataLen:=255; <br>&nbsp; &nbsp; if Length(FName)&lt;=0 then exit; <br>&nbsp; &nbsp; FName:=FName+#0; <br>&nbsp; &nbsp; InfoSize:=GetFileVersionInfoSize(@Fname[1], InfoLen); <br>&nbsp; &nbsp; if (InfoSize &gt; 0) then <br>&nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; GetMem(Info, InfoSize); <br>&nbsp; &nbsp; &nbsp; &nbsp; try <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if GetFileVersionInfo(@FName[1], InfoLen, InfoSize, Info) then <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if VerQueryValue(Info,'/VarFileInfo/Translation',LangPtr, DataLen) then <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; InfoType:=Format('/StringFileInfo/%0.4x%0.4x/%s'#0,[LoWord(LongInt(LangPtr^)), <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; HiWord(LongInt(LangPtr^)), InfoType]); <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if VerQueryValue(Info,@InfoType[1],InfoData,Datalen) then <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Result := strPas(InfoData); <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end; <br>&nbsp; &nbsp; &nbsp; &nbsp; finally <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FreeMem(Info, InfoSize); <br>&nbsp; &nbsp; &nbsp; &nbsp; end; <br>&nbsp; &nbsp; &nbsp; end; <br>&nbsp; end; <br>&nbsp; <br>&nbsp; end.<br><br>
 
多人接受答案了。
 
后退
顶部