function getFileVersionStr( const sgFileName : string ) : string; var infoSize: DWORD; var verBuf: pointer; var verSize: UINT; var wnd: UINT; var FixedFileInfo : PVSFixedFileInfo; begin infoSize := GetFileVersioninfoSize(PChar(sgFileName), wnd); result := ''; if infoSize <> 0 then begin GetMem(verBuf, infoSize); try if GetFileVersionInfo(PChar(sgFileName), wnd, infoSize, verBuf) then begin VerQueryValue(verBuf, '\', Pointer(FixedFileInfo), verSize); result := IntToStr(FixedFileInfo.dwFileVersionMS div $10000) + '.' + IntToStr(FixedFileInfo.dwFileVersionMS and $0FFFF) + '.' + IntToStr(FixedFileInfo.dwFileVersionLS div $10000) + '.' + IntToStr(FixedFileInfo.dwFileVersionLS and $0FFFF); end; finally FreeMem(verBuf); end; end; end; function getFileVersionInt( const sgFileName : string ) : Integer; var infoSize: DWORD; var verBuf: pointer; var verSize: UINT; var wnd: UINT; var FixedFileInfo : PVSFixedFileInfo; begin infoSize := GetFileVersioninfoSize(PChar(sgFileName), wnd); result := 0; if infoSize <> 0 then begin GetMem(verBuf, infoSize); try if GetFileVersionInfo(PChar(sgFileName), wnd, infoSize, verBuf) then begin VerQueryValue(verBuf, '\', Pointer(FixedFileInfo), verSize); result := StrToInt( IntToStr(FixedFileInfo.dwFileVersionMS div $10000) + IntToStr(FixedFileInfo.dwFileVersionMS and $0FFFF) + IntToStr(FixedFileInfo.dwFileVersionLS div $10000) + IntToStr(FixedFileInfo.dwFileVersionLS and $0FFFF) ); end; finally FreeMem(verBuf); end; end; end; procedure TForm1.FormCreate(Sender: TObject); begin ShowMessage(getFileVersionStr('C:\ABC.EXE')); ShowMessage(IntToStr(getFileVersionInt('D:\CDE.DLL'))); end;
網頁
▼
2013/01/09
取得所有檔案頪型的版本資訊方法
資料來源:DLL file version
沒有留言:
張貼留言