如何使用GetFileVersionInfo函数来获得一个exe的版本号(50分)

  • 主题发起人 主题发起人 okla
  • 开始时间 开始时间
O

okla

Unregistered / Unconfirmed
GUEST, unregistred user!
如何使用<br>GetFileVersionInfo<br>GetFileVersionInfoSize<br>函数来获得一个exe的版本号,能提供例子代码最好
 
来自: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>
 
接受答案了.
 
后退
顶部