目前我可以将当前的进程列表拉入我的Delphi应用程序和图像名称。我还需要查找并提取文件说明。例如,我可以这样做:
Image name Description myfile.exe
我似乎无法做到这一点:
Image name Description myfile.exe cool text about my file
我怎样才能提供说明?
答案 0 :(得分:4)
以下代码可能就是你所追求的。它使用 GetFileVersionInfoSize 和 GetFileVersionInfo 。它返回带有各种版本信息的TStringList。您可能需要 FileDescription 条目。它基于一些代码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;
只需将完整的文件名和TStringList传递给上述函数,然后您就可以执行以下操作来获取说明:
Result := ListOut.Values[viFileDescription];
编辑 - 喜欢那里的主要示例中的代码格式,不要认为它喜欢\'。