[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How can i pull date from process to delphi

Posted on 2009-07-10
12
Medium Priority
?
276 Views
Last Modified: 2012-05-07
Hi, I can pull the process image names from taskmanger into delphi but I want to also pull in the description of each file.

                                           images name      username     cpu   memory     description
for example i can pull in:     sonicT.exe      
but i want to pull in:             sonicT.exe                                                         1.1.0

If you check your own process window you will see descripton at the far raght, well I need to pull that into delphi.
This is my code to pull in image names:


procedure TForm1.Button1Click(Sender: TObject);
var
MyHandle: THandle;
Struct: TProcessEntry32;
begin
try
MyHandle:=CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
Struct.dwSize:=Sizeof(TProcessEntry32);
if Process32First(MyHandle, Struct) then
ListBox1.Items.Add(Struct.szExeFile);
while Process32Next(MyHandle, Struct) do
ListBox1.Items.Add(Struct.szExeFile);
except on exception do
ShowMessage('Error showing process list');
end
end;

Open in new window

0
Comment
Question by:SonicM3
[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
  • 9
  • 2
12 Comments
 

Author Comment

by:SonicM3
ID: 24826713
i am stuck on this people, sorry i am not patient but i am so far behind i am trying to catch up tonight, all night.  
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 24826840
what is this for ?

that's not the description, that's the file version !



function GetFileVersion(const FileName: TFileName): string;
var
  Major, Minor, Release, Build: word;
  size, len: longword;
  handle: THandle;
  buffer: pchar;
  pinfo: ^VS_FIXEDFILEINFO;
begin
    Major := 0;
    Minor := 0;
    Release := 0;
    Build := 0;
    size := GetFileVersionInfoSize(Pointer(FileName), handle);
    if size > 0 then
    begin
      GetMem(buffer, size);
      if GetFileVersionInfo(Pointer(FileName), 0, size, buffer)
      then
        if VerQueryValue(buffer, '\', pointer(pinfo), len) then
        begin
          Major   := HiWord(pinfo.dwFileVersionMS);
          Minor   := LoWord(pinfo.dwFileVersionMS);
          Release := HiWord(pinfo.dwFileVersionLS);
          Build   := LoWord(pinfo.dwFileVersionLS);
        end;
      FreeMem(buffer);
    end;
    result := Format('%d.%d.%d.%d',[Major, Minor, Release, Build]);
end;

Open in new window

0
 

Author Comment

by:SonicM3
ID: 24828286
yer i know i said i want the file description.
ignore the 1.1.0 my program shows the version inside description that was just example.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:SonicM3
ID: 24828297
just going to check the code now buddy
0
 

Author Comment

by:SonicM3
ID: 24828304
when i paste this code in its just a blank screen    any ideas?
0
 

Author Comment

by:SonicM3
ID: 24828864
i need to know how to oupput results pls into a listbox via a button.
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 24829067
do you have anything else working in your "project"
besides this listing of running programs ?
0
 

Author Comment

by:SonicM3
ID: 24829885
my project is massive..but i want to get this working in a blank project first so it outputs into a listbox when button1 is pressed.
0
 

Author Comment

by:SonicM3
ID: 24829950
uses TLHelp32

procedure TForm1.Button1Click(Sender: TObject);
var
MyHandle: THandle;
Struct: TProcessEntry32;
begin
try
MyHandle:=CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
Struct.dwSize:=Sizeof(TProcessEntry32);
if Process32First(MyHandle, Struct) then
ListBox1.Items.Add(Struct.szExeFile);
while Process32Next(MyHandle, Struct) do
ListBox1.Items.Add(Struct.szExeFile);
except on exception do
ShowMessage('Error showing process list');
end
end;



this is the code im using VB, it works tho. Can that code be fitted into this code to see fileversion. ?
0
 

Author Comment

by:SonicM3
ID: 24829972
im not using vb, i mean its VB code but works perfect in delphi too.
0
 
LVL 11

Accepted Solution

by:
dougaug earned 2000 total points
ID: 24852883
Hi SonicM3,

I've made the following code. See if it's what you are looking for.

Regards,
function GetFileDescription(FileName: string): string;
var
  FileVersionInfo: Pointer;
  FileVersionInfoSize: Cardinal;
  handle, FileInformationSize: Cardinal;
  TranslationTable: Pointer;
  FileDescription: PChar;
begin
  try
    FileVersionInfoSize := GetFileVersionInfoSize(PChar(FileName), handle);
 
    if FileVersionInfoSize = 0 then
      RaiseLastOSError;
 
    GetMem(FileVersionInfo, FileVersionInfoSize);
 
    if GetFileVersionInfo(Pchar(FileName), 0, FileVersionInfoSize, FileVersionInfo) then
    begin
       if not VerQueryValue(FileVersionInfo, '\VarFileInfo\Translation', TranslationTable, FileInformationSize) then
         RaiseLastOSError;
 
       if not VerQueryValue(FileVersionInfo,
                            PChar('StringFileInfo\' +
                            Format ('%0.4x%0.4x', [LoWord(PInt(TranslationTable)^),
                                                   HiWord(PInt(TranslationTable)^)]) +
                            '\FileDescription'),
                            Pointer(FileDescription), FileInformationSize) then
         RaiseLastOSError;
 
       Setstring(Result, FileDescription, StrLen(FileDescription));
    end;
  except
    Result := '';
  end;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
var
  ProcessSnapshotHandle, ProcessModuleSnapshotHandle: THandle;
  Struct: TProcessEntry32;
  Module: TModuleEntry32;
  FilePath: String;
begin
  ListBox1.Clear;
  try
    ProcessSnapshotHandle := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0);
    Struct.dwSize := Sizeof(TProcessEntry32);
 
    if Process32First(ProcessSnapshotHandle, Struct) then
    begin
      if Struct.th32ProcessID <> 0 then
      begin
        ProcessModuleSnapshotHandle := CreateToolHelp32SnapShot(TH32CS_SNAPMODULE, Struct.th32ProcessID);
        FilePath := Struct.szExeFile;
 
        if ProcessModuleSnapshotHandle <> Cardinal(-1) then
        begin
          Module.dwSize := Sizeof(TModuleEntry32);
 
          if Module32First(ProcessModuleSnapshotHandle, Module) then
            FilePath := Module.szExePath;
        end;
 
        ListBox1.Items.Add(String(Struct.szExeFile) + '   ' + GetFileDescription(FilePath));
      end
      else
        ListBox1.Items.Add(Struct.szExeFile);
    end;
 
    while Process32Next(ProcessSnapshotHandle, Struct) do
    begin
      if Struct.th32ProcessID <> 0 then
      begin
        ProcessModuleSnapshotHandle := CreateToolHelp32SnapShot(TH32CS_SNAPMODULE, Struct.th32ProcessID);
        FilePath := Struct.szExeFile;
 
        if ProcessModuleSnapshotHandle <> Cardinal(-1) then
        begin
          Module.dwSize := Sizeof(TModuleEntry32);
 
          if Module32First(ProcessModuleSnapshotHandle, Module) then
            FilePath := Module.szExePath;
        end;
 
        ListBox1.Items.Add(String(Struct.szExeFile) + '   ' + GetFileDescription(FilePath));
      end
      else
        ListBox1.Items.Add(Struct.szExeFile);
    end;
 
  except
    ShowMessage('Error showing process list');
  end;
end;

Open in new window

0
 

Author Closing Comment

by:SonicM3
ID: 31602219
great
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

649 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