Solved

Get Path + Version

Posted on 2000-04-03
21
276 Views
Last Modified: 2012-05-04
If I have a window title could I get the path of the file, and then could I get the version of the file? Thanks!
0
Comment
Question by:nafa2221
  • 8
  • 6
  • 5
  • +1
21 Comments
 
LVL 2

Expert Comment

by:NetoMan
Comment Utility
I think this could help you...

function GetWindowExeName(Handle: THandle): String;
 var
PE: TProcessEntry32;
 Snap: THandle;
ProcessId: cardinal;
begin
 GetWindowThreadProcessId(Handle,@ProcessId);
 Snap:= CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if Snap <> 0 then begin
 if Process32First(Snap, PE) then
  if PE.th32ProcessID = ProcessId then
  Result:= String(PE.szExeFile)
   else while Process32Next(Snap, PE) do
 if PE.th32ProcessID = ProcessId then begin
  Result:= String(PE.szExeFile);
   break;
    end;
    CloseHandle(Snap);
   end;
 end;

0
 

Author Comment

by:nafa2221
Comment Utility
I need a function that then gets the exe's version. Can u help me with that too?
0
 
LVL 2

Expert Comment

by:NetoMan
Comment Utility
The exe version is for a Delphi made program right ?





0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,Tlhelp32;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
   Notepad_Hwnd : hwnd;
implementation

{$R *.DFM}

function ReadVersionInfo(sProgram: string;
Major, Minor, Release, Build : pWord): Boolean;
var
Info: PVSFixedFileInfo;
InfoSize: Cardinal;
nHwnd: DWORD;
BufferSize: DWORD;
Buffer: Pointer;
begin
Result:=False;
BufferSize := GetFileVersionInfoSize(pchar(sProgram),nHWnd);
if BufferSize <> 0 then begin
GetMem( Buffer, BufferSize);
try
if GetFileVersionInfo(PChar(sProgram),nHWnd,BufferSize,Buffer) then begin
if VerQueryValue(Buffer, '\', Pointer(Info), InfoSize) then begin
if Assigned(Major) then Major^ := HiWord(Info^.dwFileVersionMS);
if Assigned(Minor) then Minor^ := LoWord(Info^.dwFileVersionMS);
if Assigned(Release) then Release^ := HiWord(Info^.dwFileVersionLS);
if Assigned(Build) then Build^ := LoWord(Info^.dwFileVersionLS);
Result:=True;
end;
end;
finally
FreeMem(Buffer, BufferSize);
end;
end;
end;

function GetWindowExeName(Handle: THandle): String;
var
  PE: TProcessEntry32;
  Snap: THandle;
  ProcessId: cardinal;
begin
  GetWindowThreadProcessId(Handle,@ProcessId);
  Snap:= CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  if Snap <> 0 then begin
    if Process32First(Snap, PE) then
      if PE.th32ProcessID = ProcessId then
        Result:= String(PE.szExeFile)
      else while Process32Next(Snap, PE) do
        if PE.th32ProcessID = ProcessId then begin
          Result:= String(PE.szExeFile);
          break;
        end;
    CloseHandle(Snap);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
major, minor, release, build : word;
begin
notepad_HWND := findwindow('Notepad',nil);
ShowMessage(GetWindowExeName(notepad_HWND));
ReadVersionInfo(GetWindowExeName(notepad_HWND),@major,@minor,@release,@build);
ShowMessage(Format('major: %d / minor: %d / release %d / build %d', [major,minor,release,build]));
end;

end.
0
 
LVL 2

Expert Comment

by:NetoMan
Comment Utility
This is a better way to get the version from you application:

procedure TfrmSysSplash.FormShow(Sender: TObject);
var
  MayorVersion, MinorVersion, Release, Build: Integer;
begin
  Screen.Cursor := crHourglass;
  GetFileVersion(MayorVersion, MinorVersion, Release, Build);
  AppMayorVersion := MayorVersion;
  AppMinorVersion := MinorVersion;
  AppRelease := Release;
  AppBuild := Build;
  lblFileVersion.Caption := Format('Versión %d.%s',
    [MayorVersion, FormatFloat('00', MinorVersion)]);
end;

Another thing ?
0
 

Author Comment

by:nafa2221
Comment Utility
for some reason that code does not work!!!! why dont you try it.. ;]
0
 

Author Comment

by:nafa2221
Comment Utility
I dont want it to get the version of my application!!!
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
to get a files exename you can use the handle (the same handle used for getwindowtext)therefore the GetWindowExeName function ..

note the Tlhelp32 function in the uses section.this means it wont work on all pcs as half the operating systems doint support this stuff.
..for stuff that works in all pcs see madshi web site for ideas
http://nettrash.com/users/madshi/
but madshis stuff is very complicated,  not at all recommended for beginners unless you really know what your doing.
im not kidding either as i dont understand half of it myself ;-)


0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
of course it works .
see the getFileVersionInfo() calls ?

0
 
LVL 2

Expert Comment

by:NetoMan
Comment Utility
add Tlhelp32 unit in your uses clause for the first function (Get WindowExeName)...

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Expert Comment

by:NetoMan
Comment Utility

"I dont want it to get the version of my application!!!"

"...and then could I get the version of the file"

then what do you mean with the version of the file ? any program file ?
0
 

Author Comment

by:nafa2221
Comment Utility
the version of the file that I found by the title, remember how I siad i want to find a file path by the window, then I said could I find the version of the path I just got!
0
 
LVL 17

Accepted Solution

by:
inthe earned 100 total points
Comment Utility
nafa2221 ,
what do you thing i have gave you then ??

you dont use the window title toget path you use the windows hwnd.

use used
s:= getwindowtext(somehwnd)
to get the title..

well i use
GetWindowExeName(somehwnd)..
 to get the path ..

really i have gave what the question asked...
the file path and the file version ..
0
 

Author Comment

by:nafa2221
Comment Utility
Version, none, of these examlpes work for getting version...I found a way to get the path...but I still cannot get the version. Help!
0
 
LVL 2

Expert Comment

by:gallaghe
Comment Utility
Below shows how to get all running applications captions into a TStringList. From here you can do many things, for example get the path to a particular application. Once this is done the version information can be obtained.

1) Install the component below
2) On a form, place a listbox and button
3) In the forms FormCreate event place the following code
  WinList1.Execute ;
  ListBox1.Items.Assign(  WinList1.WindowList ) ;

4) In the buttons OnClick place:
  function GetVerNoString(FileName: string): string ;
  type
    TTRANSARRAY = packed record
      LangID: WORD;
      CharSet: WORD;
    end;
    PTRANSARRAY = ^TTRANSARRAY ;
  var
    dwSize, dwZero: DWORD ;
    Buff, pVer: Pointer ;
    pTA: PTRANSARRAY ;
    LangCharSet: string ;
  begin
    Result := '' ;

    dwSize := GetFileVersionInfoSize(PChar(FileName), dwZero) ;
    GetMem(Buff, dwSize) ;
    try
      if GetFileVersionInfo(PChar(FileName), dwZero, dwSize, Buff) then
      begin
        VerQueryValue(Buff,PChar('\VarFileInfo\Translation'),Pointer(pTA),dwSize) ;
        with pTA^ do
         LangCharSet := Format('\StringFileInfo\%s%s\FileVersion',
           [IntToHex(LangID, 4), IntToHex(charset, 4)]) ;
        VerQueryValue(Buff, PChar(LangCharSet), pVer, dwSize) ;
        Result := StrPas(PChar(pVer)) ;
      end ;
    finally
     FreeMem(Buff) ;
    end ;
  end ;
var
  cFileName: String ;
  cVersion : String ;
begin
  cFileName := WinList1.GetWinExePath(ListBox1.ItemIndex) ;
  cVersion := Trim(GetVerNoString(cFileName)) ;
  if length(cVersion) >0 then
    ShowMessage('FileName=' + cFileName + #13 + 'Version=' + cVersion)
  else
    ShowMessage('FileName=' + cFileName + #13 + 'Version=???') ;
end;


Pressing the button will get the current ListBox item, pass it along to the component below and get the path and executable. From here the private function within OnClick attempts to get the file version. I tested it and in all cases but one a version number was returned out of 10 tries. There are better versionInfo components, one is from Brad Stower at http://www.delphifreestuff.com/

Here is the component needed for the above code.
{***************************************************************************}
{  Date: 22.01.97                                            Time: 17:30:40 }
{  Copyright (c)1996-1997                                                   }
{  © by Dr.Plass                                               TFindWin2.1  }
{                                                                           }
{                                              for DELPHI 2, Win95 (Not NT!)}
{  feel free to contact me:                                                 }
{  Peter.Plass@FH-Zwickau.de                                                }
{  http://www.fh-zwickau.de/~pp/tm.htm                                      }
{                                                                           }
{  All Rights Reserved.                                                     }
{  This component can be freely used and distributed in commercial and      }
{  private environments, provided this notice is not modified in any way.   }
{                                                                           }
{      based on Jerome Tremblay's component TWindowsList v1.0               }
{      --> jerome@infose.com                                                }
{                                                                           }
{  used:                                                                    }
{  ToolHelp32 v1.00  ©1996 by Brad Stowers --> bstowers@pobox.com           }
{                                                                           }
{                                                                           }
{***************************************************************************}
//
//
//  Methods:
//  procedure Execute;
//  function GetWinHandle (Idx : Integer): HWND;
//  function GetWinParent (Idx : Integer): HWND;
//  function GetThreadID  (Idx : Integer): HTask;
//  function GetIconHandle(Idx : Integer): HIcon;
//  function GetProcessID (Idx : Integer): DWORD;
//  function GetWinStyle  (Idx : Integer): LongInt;
//  function GetWinExStyl (Idx : Integer): LongInt;
//  function GetWinExePath(Idx : Integer): String;
//  function GetWnClasName(Idx : Integer): String;
//  function GetParentName(Idx : Integer): String;
//
//  e.g.: whdl := WinList1.GetWinHandle(ListBox1.ItemIndex);
//
//  Properties:
//  Property WhatDoFind : TFind_ID;
//  Property WindowList : TStringList;
//  Property EmptyNames : Boolean;
//  Property TaskBarSty : Boolean;
//  Property TimerIntval: Integer;
//  Property EnableTimer: Boolean;
//  Property OnChanged  : TNotifyEvent;
//
//


unit FindWin;
interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, toolhelp32,shellApi;

const
 cAbout = 'TFindWin2.1(32): © 1997 by Dr.Plass';
type
  TFind_ID = (id_All,id_VisOnly,id_InvisOnly);

  TWinInfo = class(TObject)
  private
  public
   hpar,
   whdl    : HWND;
   thdl    : HTask;
   Parent,
   clas,
   ExePath : String;
   hIco,
   phdl    : DWORD;
   wsty,
   wXty    : LongInt;
  end;

  TWinList = class(TComponent)
  private
   FFindID           : TFind_ID;
   fWindowsList      : TStringList;
   WinObj            : TWinInfo;
   fAcceptEmptyNames,
   fTimerOn,
   fTaskBarStyle     : Boolean;
   fOnChanged        : TNotifyEvent;
   timer1            : TTimer;
   fTimeVal          : Integer;
   fAbout            : String;
  protected
   Procedure GetWindowsInfo(WinHandle : HWND);
   procedure SomeChanged;
   procedure FuAbout(value :String);
   procedure SetTimer(value:Boolean);
   procedure SetTimeVal(value:Integer);
   procedure Timer1Timer(Sender:TObject);
  public
   Constructor Create(AOwner : TComponent); override;
   Destructor Destroy; override;
   Procedure Execute; virtual;
   function GetWinHandle(Idx : Integer): HWND;
   function GetWinParent(Idx : Integer): HWND;
   function GetThreadID (Idx : Integer): HTask;
   function GetIconHandle(Idx : Integer): HIcon;
   function GetProcessID(Idx : Integer): DWORD;
   function GetWinStyle (Idx : Integer): LongInt;
   function GetWinExStyl(Idx : Integer): LongInt;
   function GetWinExePath(Idx : Integer): String;
   function GetWnClasName(Idx : Integer): String;
   function GetParentName(Idx : Integer): String;
  published
   Property About      : String read FAbout write FuAbout;
   Property WhatDoFind : TFind_ID read FFindID write FFindID default id_visonly;
   Property WindowList : TStringList read fWindowsList write fWindowsList;
   Property EmptyNames : Boolean read fAcceptEmptyNames write fAcceptEmptyNames default False;
   Property TaskBarSty : Boolean read fTaskBarStyle write fTaskBarStyle default True;
   Property TimerIntval: Integer read fTimeVal write SetTimeVal default 500;
   Property EnableTimer: Boolean read fTimerOn write SetTimer default False;
   Property OnChanged  : TNotifyEvent read FOnChanged write FOnChanged;
  end;

function  GetStyle(hdl : HWnd):Boolean;
procedure Register;
implementation
var
 WCheck,
 nWCheck : LongInt;
 ac,ftb,
 changed : Boolean;
 fid     : TFind_ID;
 Nums    : Integer;
 aw      : array[0..255] of HWnd;


function EnumWindowsProc(hwndNext : HWnd; var lpara : LongInt):Bool;stdcall;
var
 P      : array[0..255] of Char;
 DoIt   : Boolean;
 hwPop  : HWnd;
begin
 Result := True;

 if hwndNext <> 0 then begin
  P[0] := #0;
  DoIt := False;
  GetWindowText(hwndNext, P, 255);
  if (ac or (P[0] <> #0)) then

   case fid of
    id_all      :                                         DoIt := True;
    id_visonly  : if (IsWindowVisible(hwndNext))     then DoIt := True;
    id_invisonly: if NOT (IsWindowVisible(hwndNext)) then DoIt := True;
   end;

   if (DoIt)then begin
    if NOT(ftb) then begin
     aw[Nums]:= hwndNext;
     inc (Nums);
     nWCheck := nWCheck + hwndNext;
     exit;
    end;
    if (GetWindow(hwndNext, GW_OWNER) = 0) then
     if GetStyle(hwndNext) then begin
      aw[Nums]:= hwndNext;
      inc (Nums);
      nWCheck := nWCheck + hwndNext;
     end
     else if isWindow(GetLastActivePopup(hwndNext))then begin
       hwPop := GetLastActivePopup(hwndNext);
       if GetStyle(hwPop) then begin
        aw[Nums]:= hwndNext;
        inc (Nums);
        nWCheck := nWCheck + hwndNext;
       end;
     end;
   end;
  end else Result := False;
end;

Constructor TWinList.Create(AOwner : TComponent);
Begin
 inherited Create(AOwner);
 fWindowsList      := TStringList.Create;
 timer1            := TTimer.Create(self);
 timer1.OnTimer    := Timer1Timer;
 timer1.Enabled    := False;
 fAcceptEmptyNames := False;
 fTimeVal          := 500;
 fTimerOn          := False;
 fFindId           := id_visonly;
 fTaskBarStyle     := True;
 WCheck            := 0;
 fAbout            := '';
 changed           := True;
End;

Destructor TWinList.Destroy;
Begin
 fWindowsList.Clear;
 fWindowsList.Free;
 WinObj.Free;
 WinObj := NIL;
 timer1.Enabled := False;
 timer1.Free;
 inherited Destroy;
End;

Procedure TWinList.GetWindowsInfo(WinHandle : HWND);
var
 P      : array[0..256] Of Char;
 dwActiveProcessId : DWORD;
 snap   : THandle;
 pe32   : TPROCESSENTRY32;
Begin
 P[0] := #0; snap := 0;
 WinObj      := TWinInfo.Create;

 WinObj.whdl := WinHandle;
 WinObj.thdl := GetWindowThreadProcessId(WinHandle,NIL);
 GetWindowThreadProcessId(WinHandle, @dwActiveProcessId );
 WinObj.phdl := dwActiveProcessId;
 WinObj.wsty := GetWindowLong(WinHandle,GWL_STYLE);
 WinObj.wXty := GetWindowLong(WinHandle,GWL_EXSTYLE);
 WinObj.hPar := GetWindowLong(WinHandle,GWL_HWNDPARENT);
 GetClassName(WinHandle, P, 100);
 WinObj.clas := String(P);

 if WinObj.hPar = 0 then P := 'Desktop'
 else               GetWindowText(WinObj.hPar, P, 255);
 if P='' then P := 'NoName';
 WinObj.Parent := String(P);

 GetWindowText(WinHandle, P, 255);
 try
  snap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,
                                   dwActiveProcessId);
  if snap <> 0 then begin
   pe32.dwSize := SizeOf(TPROCESSENTRY32);
   if Process32First(snap, pe32) then begin
    if pe32.th32ProcessID = dwActiveProcessId then begin
     WinObj.ExePath := String(pe32.szExeFile);
     // and so on ProcessEntry
    end else begin
     while Process32Next(snap, pe32) do begin
      if pe32.th32ProcessID = dwActiveProcessId then begin
       WinObj.ExePath := String(pe32.szExeFile);
       // and so on ProcessEntry
       break;
      end;
     end;
    end;
    {WinObj.hIco := LoadIcon(0, MakeIntResource(IDI_WinLogo));}
    WinObj.hIco := ExtractIcon(hInstance,pe32.szExeFile,0);
   end;
  end;
 finally
  CloseHandle(snap);
 end;
 fWindowsList.AddObject(P, WinObj);
End;

Procedure TWinList.Execute;
var
 i : Integer;
Begin
 nWCheck := 0;
 timer1.Enabled := False;
 ac   := fAcceptEmptyNames;
 fid  := FFindID;
 ftb  := fTaskBarStyle;
 Nums := 0;

 EnumWindows(@EnumWindowsProc,0);

 if WCheck <> nWCheck then begin
  WCheck  := nWCheck;
  fWindowsList.Clear;
   for i := 0 to Nums - 1 do
    GetWindowsInfo(aw[i]);
  changed := True;
 end else changed := False;
 if fTimerOn then timer1.Enabled := True;
End;

procedure TWinList.SomeChanged;
begin
 if Assigned(FOnChanged) then FOnChanged(Self);
end;

procedure TWinList.Timer1Timer(Sender:TObject);
begin
 if fTimeVal < 1 then timer1.Enabled := False;
 Execute;
 Application.ProcessMessages;
 if changed then SomeChanged;
end;

procedure TWinList.FuAbout(value:String);
begin
 if value <> fAbout then begin
  fAbout := cAbout;

  {MessageDlg('Komponente: TFindWin2.1[32]         '+ #10#13+ #10#13+
             '©1997 by Dr.Plass                   '+ #10#13+
             'Peter.Plass@fh-zwickau.de           '+ #10#13+
             'http://www.fh-zwickau.de/~pp/tm.htm ',
              mtInformation, [mbOk],0);}
  end;
end;

procedure TWinList.SetTimer(value:Boolean);
begin
 if value <> fTimerOn then begin
  fTimerOn       := value;
  timer1.Enabled := fTimerOn;
 end;
end;

procedure TWinList.SetTimeVal(value: Integer);
begin
 if value < 1 then  EnableTimer:= False;
 if value <> fTimeVal then begin
  fTimeVal        := value;
  timer1.Interval := fTimeVal;
 end;
end;

function TWinList.GetWinParent(Idx : Integer) : HWND;
begin
  Result := TWinInfo(fWindowsList.Objects[Idx]).hpar;
end;
function TWinList.GetWinHandle(Idx : Integer) : HWND;
begin
  Result := TWinInfo(fWindowsList.Objects[Idx]).whdl;
end;
function TWinList.GetThreadID(Idx : Integer) : HTask;
begin
  Result := TWinInfo(fWindowsList.Objects[Idx]).thdl;
end;
function TWinList.GetIconHandle(Idx : Integer) : HIcon;
begin
  Result := TWinInfo(fWindowsList.Objects[Idx]).hIco;
end;
function TWinList.GetProcessID(Idx : Integer) : DWORD;
begin
  Result := TWinInfo(fWindowsList.Objects[Idx]).phdl;
end;
function TWinList.GetWinStyle(Idx : Integer) : LongInt;
begin
  Result := TWinInfo(fWindowsList.Objects[Idx]).wsty;
end;
function TWinList.GetWinExStyl(Idx : Integer) : LongInt;
begin
  Result := TWinInfo(fWindowsList.Objects[Idx]).wXty;
end;
function TWinList.GetWinExePath(Idx : Integer): String;
begin
  Result := TWinInfo(fWindowsList.Objects[Idx]).ExePath;
end;
function TWinList.GetWnClasName(Idx : Integer): String;
begin
 Result := TWinInfo(fWindowsList.Objects[Idx]).clas;
end;
function TWinList.GetParentName(Idx : Integer): String;
begin
 Result := TWinInfo(fWindowsList.Objects[Idx]).Parent;
end;

function GetStyle(hdl : HWnd):Boolean;
var
 style : LongInt;
BEGIN
 Result := False;
 style  := GetWindowLong(hdl,GWL_STYLE);
 if((  style AND WS_POPUP)    = WS_POPUP) then  begin
  if(((style AND WS_GROUP)    = WS_GROUP)       AND NOT
     ((style AND WS_DISABLED) = WS_DISABLED)    AND
     ((style AND WS_SYSMENU)  = WS_SYSMENU))    then
     Result := True;
 end else Result := True;
END;

procedure Register;
begin
  RegisterComponents('Win32', [TWinList]);
end;
end.




NOTE: I have been using the above component in a "System Information" freeware utility which can be downloaded from Brad's site (listed above). This utility shows some other possiblities of the component TWinList.

Yell if you need more help
Kevin

0
 
LVL 2

Expert Comment

by:gallaghe
Comment Utility
Ooops here is is another unit which goes along with the above.

{-----------------------------------------------------------------------------}
{ An import unit to expose the ToolHelp32 functions.                          }
{                                                                             }
{ NOTE!!!  This only works on Win95.  NT 3.5x does not provide these          }
{ functions in Kernel32.dll (or anywhere as far as I know).  I do not know    }
{ about NT 4.0, you are on your own there.                                    }
{                                                                             }
{ Copyright 1996, Brad Stowers.  All Rights Reserved.                         }
{ This unit can be freely used and distributed in commercial and private      }
{ environments, provied this notice is not modified in any way and there is   }
{ no charge for it other than nomial handling fees.  Contact me directly for  }
{ modifications to this agreement.                                            }
{-----------------------------------------------------------------------------}
{ Feel free to contact me if you have any questions, comments or suggestions  }
{ at bstowers@pobox.com or 72733,3374 on CompuServe.                          }
{ The lateset version will always be available on the web at:                 }
{   http://www.pobox.com/~bstowers/delphi/                                    }
{-----------------------------------------------------------------------------}
{ Date last modified:  10/19/96                                               }
{-----------------------------------------------------------------------------}

{ ----------------------------------------------------------------------------}
{ ToolHelp32 v1.00                                                            }
{ ----------------------------------------------------------------------------}
{ Revision History:                                                           }
{ 1.00:  + Initial release.                                                   }
{          The comments in this unit are from the SDK.                        }
{ ----------------------------------------------------------------------------}

unit ToolHelp32;

{$IFNDEF WIN32}
  ERROR!  This unit only available on Win32!
{$ENDIF}

interface

uses Windows;

const
  MAX_MODULE_NAME32 = 255;

function CreateToolhelp32Snapshot(dwFlags, th32ProcessID: DWORD): THandle; stdcall;
//
// The th32ProcessID argument is only used if TH32CS_SNAPHEAPLIST or
// TH32CS_SNAPMODULE is specified. th32ProcessID == 0 means the current
// process.
//
// NOTE that all of the snapshots are global except for the heap and module
//      lists which are process specific. To enumerate the heap or module
//      state for all WIN32 processes call with TH32CS_SNAPALL and the
//      current process. Then for each process in the TH32CS_SNAPPROCESS
//      list that isn't the current process, do a call with just
//      TH32CS_SNAPHEAPLIST and/or TH32CS_SNAPMODULE.
//
// dwFlags
//
const
  TH32CS_SNAPHEAPLIST = $00000001;
  TH32CS_SNAPPROCESS  = $00000002;
  TH32CS_SNAPTHREAD   = $00000004;
  TH32CS_SNAPMODULE   = $00000008;
  TH32CS_SNAPALL          = TH32CS_SNAPHEAPLIST or TH32CS_SNAPPROCESS or
                        TH32CS_SNAPTHREAD or TH32CS_SNAPMODULE;
  TH32CS_INHERIT          = $80000000;
//
// Use CloseHandle to destroy the snapshot
//


(****** heap walking ***************************************************)

type
  PHEAPLIST32 = ^THEAPLIST32;
  THEAPLIST32 = packed record
    dwSize,
    th32ProcessID,    // owning process
    th32HeapID,           // heap (in owning process's context!)
    dwFlags: DWORD;
  end;

//
// dwFlags
//
const
  HF32_DEFAULT = 1;  // process's default heap
  HF32_SHARED  = 2;  // is shared heap

function Heap32ListFirst(hSnapshot: THandle; const lphl: THEAPLIST32): boolean; stdcall;
function Heap32ListNext(hSnapshot: THandle; const lphl: THEAPLIST32): boolean; stdcall;

type
  PHEAPENTRY32 = ^THEAPENTRY32;
  THEAPENTRY32 = packed record
    dwSize: DWORD;
    hHandle: THandle;      // Handle of this heap block
    dwAddress,            // Linear address of start of block
    dwBlockSize,      // Size of block in bytes
    dwFlags,
    dwLockCount,
    dwResvd,
    th32ProcessID,    // owning process
    th32HeapID: DWORD;// heap block is in
  end;

//
// dwFlags
//
const
  LF32_FIXED    = $00000001;
  LF32_FREE     = $00000002;
  LF32_MOVEABLE = $00000004;

function Heap32First(const lphe: THEAPENTRY32; th32ProcessID, th32HeapID: DWORD): boolean; stdcall;
function Heap32Next(const lphe: THEAPENTRY32): boolean; stdcall;
function Toolhelp32ReadProcessMemory(th32ProcessID: DWORD;
                                     lpBaseAddress, lpBuffer: pointer;
                                     cbRead: DWORD;
                                     lpNumberOfBytesRead: PDWORD): boolean; stdcall;

(***** Process walking *************************************************)

type
  PPROCESSENTRY32 = ^TPROCESSENTRY32;
  TPROCESSENTRY32 = packed record
    dwSize,
    cntUsage,
    th32ProcessID,                  // this process
    th32DefaultHeapID,
    th32ModuleID,                   // associated exe
    cntThreads,
    th32ParentProcessID: DWORD; // this process's parent process
    pcPriClassBase: LongInt;    // Base priority of process's threads
    dwFlags: DWORD;
    szExeFile: array[0..MAX_PATH-1] of char;    // Path
  end;

const
  PCB_IDLE = 4;
  PCB_NORMAL = 8;
  PCB_HIGH = 13;
  PCB_REALTIME = 24;

function Process32First(hSnapshot: THandle; const lppe: TPROCESSENTRY32): boolean; stdcall;
function Process32Next(hSnapshot: THandle; const lppe: TPROCESSENTRY32): boolean; stdcall;

(***** Thread walking **************************************************)

type
  PTHREADENTRY32 = ^TTHREADENTRY32;
  TTHREADENTRY32 = packed record
    dwSize,
    cntUsage,
    th32ThreadID,                   // this thread
    th32OwnerProcessID: DWORD; // Process this thread is associated with
    tpBasePri,
    tpDeltaPri: LongInt;
    dwFlags: DWORD;
  end;

function Thread32First(hSnapshot: THandle; const lpte: TTHREADENTRY32): boolean; stdcall;
function Thread32Next(hSnapshot: THandle; const lpte: TTHREADENTRY32): boolean; stdcall;

(***** Module walking *************************************************)

type
  PMODULEENTRY32 = ^TMODULEENTRY32;
  TMODULEENTRY32 = packed record
    dwSize,
    th32ModuleID,              // This module
    th32ProcessID,              // owning process
    GlblcntUsage,              // Global usage count on the module
    ProccntUsage: DWORD;      // Module usage count in th32ProcessID's context
    modBaseAddr: PBYTE;       // Base address of module in th32ProcessID's context
    modBaseSize: DWORD;        // Size in bytes of module starting at modBaseAddr
    hModule: HMODULE;              // The hModule of this module in th32ProcessID's context
    szModule: array [0..MAX_MODULE_NAME32] of char;
    szExePath: array [0..MAX_PATH-1] of char;
  end;

//
// NOTE CAREFULLY that the modBaseAddr and hModule fields are valid ONLY
// in th32ProcessID's process context.
//

function Module32First(hSnapshot: THandle; const lpme: TMODULEENTRY32): boolean; stdcall;
function Module32Next(hSnapshot: THandle; const lpme: TMODULEENTRY32): boolean; stdcall;

implementation

function CreateToolhelp32Snapshot; external 'kernel32.dll' name 'CreateToolhelp32Snapshot';
function Heap32ListFirst; external 'kernel32.dll' name 'Heap32ListFirst';
function Heap32ListNext; external 'kernel32.dll' name 'Heap32ListNext';
function Heap32First; external 'kernel32.dll' name 'Heap32First';
function Heap32Next; external 'kernel32.dll' name 'Heap32Next';
function Toolhelp32ReadProcessMemory; external 'kernel32.dll' name 'Toolhelp32ReadProcessMemory';
function Process32First; external 'kernel32.dll' name 'Process32First';
function Process32Next; external 'kernel32.dll' name 'Process32Next';
function Thread32First; external 'kernel32.dll' name 'Thread32First';
function Thread32Next; external 'kernel32.dll' name 'Thread32Next';
function Module32First; external 'kernel32.dll' name 'Module32First';
function Module32Next; external 'kernel32.dll' name 'Module32Next';

end.

0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
how can you propose that as an answer?
did i not already give an example of using getfileversioninfo and it was rejected .
0
 

Author Comment

by:nafa2221
Comment Utility
I dont know why but the get fileversion info command doesnot work INTTHE...if you could help me get it to work I would be happy to give you the points :}
0
 

Author Comment

by:nafa2221
Comment Utility
Can you please post exatly how to use the getfileversioninfo string. I just cant get it to work...
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
hi
leave you mail adress ,it is easier for me to send you example project i have.
cheers Barry

ps what version of delphi do you have ?
0
 

Author Comment

by:nafa2221
Comment Utility
E-MAIL: Geffon4@Gte.net
Delphi 5 Enterprise Edition ;]
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now