Solved

File version info

Posted on 1998-08-21
2
549 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
[X]
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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

687 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