Solved

File version info

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

896 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