Reputation:
As it stands I can pull the current list of processes into my Delphi application and the image name. I need to also find and pull in the file description. For example, I can do this:
Image name Description myfile.exe
i can't seem to do this:
Image name Description myfile.exe cool text about my file
How can I pull in the description also?
Upvotes: 2
Views: 566
Reputation: 2631
The following code might be what you're after. It uses GetFileVersionInfoSize and GetFileVersionInfo. It returns a TStringList with the various bits of version info. You'll must likely want the FileDescription entry. It's based on some code from the Delphi section of About.com.
const
// Version Info sections as stored in Exe
viCompanyName = 'CompanyName';
viFileDescription = 'FileDescription';
viFileVersion = 'FileVersion';
viInternalName = 'InternalName';
viLegalCopyRight = 'LegalCopyright';
viLegalTradeMarks = 'LegalTradeMarks';
viOriginalFilename = 'OriginalFilename';
viProductName = 'ProductName';
viProductVersion = 'ProductVersion';
viComments = 'Comments';
viAuthor = 'Author';
VersionInfoNum = 11;
VersionInfoStr : array [1..VersionInfoNum] of String =
(viCompanyName,
viFileDescription,
viFileVersion,
viInternalName,
viLegalCopyRight,
viLegalTradeMarks,
viOriginalFilename,
viProductName,
viProductVersion,
viComments,
viAuthor
);
function GetFileVersionInformation(FileName : string; ListOut : TStrings) : boolean;
// Code based on the following from About.com / Delphi:
// http://delphi.about.com/cs/adptips2001/a/bltip0701_4.htm
//
// Related: http://www.delphidabbler.com/articles?article=20&printable=1
var
n, Len : DWord;
j : Integer;
Buf : PChar;
Value : PChar;
begin
Result := false;
ListOut.Clear;
n := GetFileVersionInfoSize(PChar(FileName), n);
if n > 0 Then
begin
Buf := AllocMem(n);
try
ListOut.Add('Size='+IntToStr(n));
GetFileVersionInfo(PChar(FileName),0,n,Buf);
for j:=1 To VersionInfoNum Do
begin
// this was originally working out the Locale ID for United States ($0409)
// where as we want United Kingdom ($0809)
// See notes for Chapter 22, page 978 - http://www.marcocantu.com/md4/md4update.htm
//if VerQueryValue(Buf,PChar('StringFileInfo\040904E4\'+
// InfoStr[j]),Pointer(Value),Len) then
if VerQueryValue(Buf, PChar('StringFileInfo\080904E4\' + VersionInfoStr[j]), Pointer(Value), Len) then
begin
if Length(Value) > 0 Then
begin
ListOut.Add(VersionInfoStr[j] + '=' + Value);
end;
end;
end;
finally
FreeMem(Buf,n);
Result := True;
end;
end;
end;
Just pass in the full file name and a TStringList to the above function, then you can just do the following to get the description:
Result := ListOut.Values[viFileDescription];
Edit - Love the code formatting in the main example there, don't think it liked the \'.
Upvotes: 4