[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

File version info

Posted on 1998-08-21
2
Medium Priority
?
556 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 400 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
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 a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

650 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