Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

File version info

Posted on 1998-08-21
2
546 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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