const
  MAJOR=0;
  MINOR=1;
  BUILD_NO=2;
  REVISION=3;

function GetVersion(FilePath: String; VerType: Integer): Integer;
var
  InfoSize: Integer;
  dwH: DWORD;
  Buf: PChar;
  pFileInfo: PVsFixedFileInfo;
  Len: UINT;
begin
  Result:=0;

  // 파일존재여부 검사
  if not FileExists(FilePath) then Exit;

  InfoSize:=GetFileVersionInfo(PChar(FilePath), dwH);
  if InfoSize=0 then Exit;

  GetMem(Buf, InfoSize);
 
  if GetFileVersionInfo(PChar(FilePath), 0, InfoSize, Buf) then begin
    if
VerQueryValue(Buf, '\\', Pointer(pFileInfo), Len) then begin
      case
VerType of
        MAJOR: Result:=HiWord(pFileInfo.dwFileVersionMS);
        MINOR: Result:=LoWord(pFileInfo.dwFileVersionMS);
        BUILD_NO: Result:=HiWord(pFileInfo.dwFileVersionLS);
        REVISION: Result:=LoWord(pFileInfo.dwFileVersionLS);
      end;
    end;
  end;

  FreeMem(Buf);
end;


// 메이저 버전 가져오기
VerMajor:=GetVersion('C:\MyTest.exe', MAJOR);
// 빌드번호 가져오기
BuildNo:=GetVersion('C:\MyTest.exe', BUILD_NO);





Posted by bloodguy
,