Solved

File version info

Posted on 1998-08-21
2
539 Views
Last Modified: 2010-04-04
Need source code or component for Delphi 4.0 that gets the version info (data, time, version, company, etc) of a file (exe, dll, etc).
0
Comment
Question by:mdlittle
2 Comments
 

Accepted Solution

by:
dangage earned 200 total points
ID: 1337434
attached are two version; the First GetFileVersion is preferred, though the OldgetFileVersion may work as well.

function GetFileVersion(pFile: PChar) : string;
begin
result := GetFileInfo(pFile, C_FILE);
end;

function GetProductVersion(pFile: PChar) : string;
begin
result := GetFileInfo(pFile, C_Product);
end;

function GetFileInfo(pFile:Pchar; C_PRODUCT_OR_FILE : integer) : string;
var InfoSize, itemLen : integer;
    FixedFileInfo : PVSFixedFileInfo;
    Wnd: HWND;
    pInfo : pointer;
    function Normalize(tempStr : string) : string;
    begin
    // remove trailing zeros or periods
    while ((copy(TempStr, length(TempStr), 1)='0') or (copy(TempStr, length(TempStr), 1)='.')) do
          TempStr := copy(TempStr, 1, length(TempStr)-1);
    result := TempStr;
    end;
begin
result := 'N/A';
InfoSize := GetFileVersionInfoSize(pFile, Wnd);
if InfoSize <> 0 then
   begin
   GetMem(pInfo, InfoSize);
   try
      if not GetFileVersionInfo(pFile, Wnd, InfoSize, pInfo) then
         exit;
      if VerQueryValue(pInfo, '\', Pointer(FixedFileInfo), itemLen) then
         begin

         case C_PRODUCT_OR_FILE of
              C_FILE    : // File Version
                 result := Normalize(IntToStr(HIWORD(FixedFileInfo^.dwFileVersionMS)) +
                           '.' + IntToStr(LOWORD(FixedFileInfo^.dwFileVersionMS)) +
                           '.' + IntToStr(HIWORD(FixedFileInfo^.dwFileVersionLS)) +
                           '.' + IntToStr(LOWORD(FixedFileInfo^.dwFileVersionLS)));
              C_PRODUCT : // Product Version
                 result := Normalize(IntToStr(HIWORD(FixedFileInfo^.dwProductVersionMS)) +
                           '.' + IntToStr(LOWORD(FixedFileInfo^.dwProductVersionMS)) +
                           '.' + IntToStr(HIWORD(FixedFileInfo^.dwProductVersionLS)) +
                           '.' + IntToStr(LOWORD(FixedFileInfo^.dwProductVersionLS)));
              else result := 'N/A';
              end;
         end;
      finally
         FreeMem(pInfo);
      end;
   end;
end;

function OldGetFileVersion(pFile: PChar) : string;
// mothod provided in C by Roy Enneper
var InfoSize: DWORD;
    Wnd: HWND;
    VerBuf: Pointer;
    sSectionName, sVersion : string;
    bOK : boolean;
    iLength : DWord;
    lpFullLabel : array[0..255] of char;
    lpVersion : pointer;
begin
sVersion := 'N/A';
sSectionName := 'FileVersion';
result := sVersion;
InfoSize := GetFileVersionInfoSize(pFile, Wnd);
if InfoSize <> 0 then
   begin
   GetMem(VerBuf, InfoSize);
   try
      if not GetFileVersionInfo(pFile, Wnd, InfoSize, VerBuf) then
         exit;
      // US
      strPcopy(lpFullLabel,'\StringFileInfo\040904E4\'+sSectionName);

      bOk := VerQueryValue(VerBuf, lpFullLabel, lpVersion, iLength);
      if (not bOk) then
         begin // Canada
         strPcopy(lpFullLabel,'\StringFileInfo\040904b0\'+sSectionName);
         bOk := VerQueryValue(VerBuf,lpFullLabel,lpVersion, iLength);
         end;
      if (bOk) then
         sVersion := LPSTR(lpVersion); // result value as a str
   finally
     FreeMem(VerBuf);
   end;
   end;
Result := sVersion;
end;

0
 
LVL 1

Expert Comment

by:EmmDieh
ID: 1337435
How about
http://sunsite.icm.edu.pl/delphi/ftp/d10free/sverinfo.zip
or
http://sunsite.icm.edu.pl/delphi/ftp/d30free/verinfo.zip
it shouldn't be a problem to compile them with D4 or
modify them.

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now