有关引入流程信息delphi的问题? [英] question about pulling in process info delphi?

查看:55
本文介绍了有关引入流程信息delphi的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按现状,我可以将当​​前进程列表放入我的Delphi应用程序和映像名称中.我还需要查找并拉入文件描述.例如,我可以这样做:

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?

推荐答案

下面的代码可能就是您想要的.它使用 GetFileVersionInfoSize GetFileVersionInfo .它返回一个TStringList,其中包含版本信息的各个位.您可能必须要 FileDescription 条目.它基于About.com的Delphi部分中的一些代码.

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;

只需将完整的文件名和一个TStringList传递给上面的函数,那么您只需执行以下操作即可获得描述:

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 \'.

这篇关于有关引入流程信息delphi的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆