Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2005.01.23;
Скачать: CL | DM;

Вниз

Процесы в Windows ..   Найти похожие ветки 

 
Chlavik ©   (2004-12-05 20:15) [0]

Как получить список процесов в Windows. Есть что то типа EnumProcesses ??


 
Xaker ©   (2004-12-05 20:19) [1]

Chlavik ©   (05.12.04 20:15)
есть


 
novice__man   (2004-12-05 20:20) [2]

Что то вроде этого:

procedure TForm1.Button1Click(Sender: TObject);
var
 Wnd: hWnd;
 buff: array[0..127] of Char;
begin
 ListBox1.Clear;
 Wnd := GetWindow(Handle, gw_HWndFirst);
 while Wnd <> 0 do begin {Не показываем:}
   if (Wnd <> Application.Handle) and {-Собственное окно}
     IsWindowVisible(Wnd) and {-Невидимые окна}
     (GetWindow(Wnd, gw_Owner) = 0) and {-Дочернии окна}
     (GetWindowText(Wnd, buff, sizeof(buff)) <> 0) {-Окна без заголовков}
     then begin
     GetWindowText(Wnd, buff, sizeof(buff));
     ListBox1.Items.Add(StrPas(buff));
   end;
   Wnd := GetWindow(Wnd, gw_hWndNext);
 end;
 ListBox1.ItemIndex := 0;
end;


 
Chlavik ©   (2004-12-05 20:24) [3]

Ты что потерялись ??? Причём тут окна (слышал про EnumWindows?).


 
Xaker ©   (2004-12-05 20:24) [4]

комплексная прога исследования процессов

unit Unit1;

interface

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

type
 TForm1 = class(TForm)
   Memo1: TMemo;
   Button1: TButton;
   Button2: TButton;
   Button3: TButton;
   CheckBox1: TCheckBox;
   Button4: TButton;
   CheckBox2: TCheckBox;
   procedure Button1Click(Sender: TObject);
   procedure Button2Click(Sender: TObject);
   procedure Button3Click(Sender: TObject);
   procedure FormCreate(Sender: TObject);
   procedure Button4Click(Sender: TObject);
   procedure FormClick(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 end;

var
 Form1: TForm1;

implementation

{$R *.dfm}
Uses  PSAPI, TlHelp32;

type

TUnicodeString = packed record
  Length, MaximumLength: Word;
  Buffer: PWideChar;
end;

PSystemProcessInformation = ^TSystemProcessInformation;
TSystemProcessInformation = packed record
  dNext: DWord;
  dThreadCount: DWord;
  dReserved01, dReserved02, dReserved03, dReserved04, dReserved05, dReserved06: DWord;
  qCreateTime, qUserTime, qKernelTime: Int64;
  usName: TUnicodeString;
  BasePriority: DWord;
  dUniqueProcessId: DWord;
  dInheritedFromUniqueProcessId: DWord;
  dHandleCount: DWord;
  dReserved07: DWord;
  dReserved08: DWord;
  VmCounters: array[0..10] of DWord;
  dCommitCharge: DWord;
end;

function NtQuerySystemInformation(sic: DWord; Buffer: Pointer; BufSize: DWord; var BytesReturned: DWord): DWord; stdcall; external "ntdll.dll";

Var Th:boolean;

procedure GetProcessList(var sl:TStrings);
var
 pe:TProcessEntry32;
 ph, snap:THandle;//дескрипторы процесса и снимка
 mh:hmodule;//дескриптор модуля
 procs:array[0..$fff] of dword;//массив для хранения дескрипторов процессов
 count, cm:cardinal;//количество процессов
 i:integer;
 ModName:array[0..max_path] of char;//имя модуля
begin
 sl.Clear;
 if not th {Win32Platform = VER_PLATFORM_WIN32_WINDOWS} then begin //если это Win9x
   snap:=CreateToolhelp32Snapshot(th32cs_snapprocess, 0);
   if integer(snap)=-1 then
   begin
     exit;
   end else
   begin
     pe.dwSize:=sizeof(pe);
     if Process32First(snap, pe) then
     repeat

   if Form1.CheckBox2.Checked then
Begin

ph:=OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,                      false,pe.th32ProcessID);
     if ph>0 then
     begin
       EnumProcessModules(ph, @mh, 4, cm);
       GetModuleFileNameEx(ph, mh, ModName, sizeof(ModName));
       if form1.CheckBox1.Checked then  sl.Add(ExtractFileName(string(ModName)))
                       else              sl.Add(string(ModName));
       CloseHandle(ph);
     end;
End

else   Begin    sl.Add(string(pe.szExeFile));     End;

     until not Process32Next(snap, pe);
   end;
 end
 else
 begin //Если WinNT/2000/XP
   if not EnumProcesses(@procs, sizeof(procs), count) then
   begin
     exit;
   end;
   for i := 0 to count div 4 - 1 do
   begin
     ph:=OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,
                     false, procs[i]);
     if ph>0 then
     begin
       EnumProcessModules(ph, @mh, 4, cm);
       GetModuleFileNameEx(ph, mh, ModName, sizeof(ModName));
       if form1.CheckBox1.Checked then  sl.Add(ExtractFileName(string(ModName)))
                       else              sl.Add(string(ModName));
       CloseHandle(ph);
     end;
   end;
 end;
end;

function FindProcess: DWord;
var
p, Buf: PSystemProcessInformation;
BufSize: DWord;
TableSize: DWord;
begin
Form1.Memo1.Clear;
Result := 0;
BufSize := $10000;
GetMem(Buf, BufSize);
while NtQuerySystemInformation(5, Buf, BufSize, TableSize) <> 0 do
  begin
    Inc(BufSize, $10000);
    ReallocMem(Buf, BufSize);
  end;
p := Buf;
while True do
  begin
    {if CompareText(Buf.usName.Buffer, ProcessName) = 0 then
      begin
        Result := Buf.dUniqueProcessId;
        break;
      end; }
    Form1.Memo1.Lines.Add(Buf.usName.Buffer);
    if Buf.dNext = 0 then Break;
    Inc(Integer(Buf), Buf.dNext);
  end;
FreeMem(p);
end;

procedure TForm1.Button1Click(Sender: TObject);
var tmp: TStrings;
begin
 Th:=True;
 tmp:=Memo1.Lines;
 GetProcessList(tmp);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
FindProcess;
end;

procedure TForm1.Button3Click(Sender: TObject);
var tmp: TStrings;
begin
 Th:=False;
 tmp:=Memo1.Lines;
 GetProcessList(tmp);
end;

function SetDebugPriv:Boolean;
var
Token: THandle;
tkp: TTokenPrivileges;
begin
Result := false;
if OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, Token) then
begin
 if LookupPrivilegeValue(nil, PChar("SeDebugPrivilege"), tkp.Privileges[0].Luid) then
 begin
   tkp.PrivilegeCount := 1;
   tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
   Result := AdjustTokenPrivileges(Token, false, tkp, 0, PTokenPrivileges(nil)^, PDWord(nil)^);
 end;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
SetDebugPriv;
end;

{uses tlHelp32;

function GetFilePath(const WinH: THandle): String;
var
SnapshotH: THandle;
PE32: TProcessEntry32;
PrId: Cardinal;
begin

Result := "";
SnapshotH := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if SnapshotH = -1 then Exit;
PE32.dwSize := SizeOf(PE32);
GetWindowThreadProcessID(WinH, PrId);
if Process32First(SnapshotH, PE32) then
repeat
if PE32.th32ProcessID = PrId then begin
 Result := PE32.szExeFile;
 Break;
end;
until not Process32Next(SnapshotH, PE32);
CloseHandle(SnapshotH)

end;

c:\DELPHI\Delphi_info\Delphi_download\html faq\102!!!!!!!!!!!!!!1.htm
}

procedure TForm1.Button4Click(Sender: TObject);

procedure SortDate(L, R: Integer);
var i,j,p: Integer;  temp: String;
begin
  repeat
    I:= L;  J:=R; P:=(L+R)shr 1;
    repeat
      while(memo1.Lines[I]<memo1.Lines[P])do Inc(I);


 
Xaker ©   (2004-12-05 20:24) [5]

      while(memo1.Lines[J]>memo1.Lines[P])do Dec(J);
      if I<=J then begin
        temp:=memo1.Lines[I];
        memo1.Lines[I]:=memo1.Lines[J];
        memo1.Lines[J]:=temp;
        if P=I then P:=J else if P=J then P:=I; Inc(I); Dec(J);
      end;
    until I>J;
    if L<J then SortDate(L,J); L:=I;
  until I>=R;
end;

begin
SortDate(0,Memo1.Lines.Count-1);
end;

procedure TForm1.FormClick(Sender: TObject);
begin
Caption:=IntToStr(Memo1.Lines.count);
end;

End.


 
Xaker ©   (2004-12-05 20:25) [6]

прикольно MF разделил ...   Респект Piter"у


 
Chlavik ©   (2004-12-05 20:27) [7]

Слушай дай уже тады проэкт [email protected]


 
novice__man   (2004-12-05 20:29) [8]

Шлавик а вы хамло.


 
Chlavik ©   (2004-12-05 20:33) [9]

Больше не буду .. Не вижу связи с вашим ответом и омим вопросом ...


 
novice__man   (2004-12-05 20:36) [10]

Сходи на сайт там есть пример, я сейчас проверил.
http://www.delphiworld.narod.ru/

Раздел: процессы и сервисы.
"Как получить хэндлы всех пpоцессов, котоpые запущены на данный момент в системе  
--------------------------------------------------------------------------------

Под Windows 95 это возможно с использованием вспомогательных инфоpмационных функций (tool help functions). Для получения списка пpоцессов надо делать следующее: .....

"


 
Chlavik ©   (2004-12-05 20:49) [11]

Да вот этот пример уже хорошо пашет ...  Process32First - то что мне надо было это и есть tool Help функция ...А у меня стоит XP так что всё ok. Thank"s ...



Страницы: 1 вся ветка

Текущий архив: 2005.01.23;
Скачать: CL | DM;

Наверх




Память: 0.5 MB
Время: 0.032 c
6-1099288139
RomCom
2004-11-01 08:48
2005.01.23
Socket -> Proxy и адреса удаленных серверов


14-1104786470
KilkennyCat
2005-01-04 00:07
2005.01.23
Чисто админский вопрос.


1-1105542768
race1
2005-01-12 18:12
2005.01.23
свойства


1-1104867226
LIMBO
2005-01-04 22:33
2005.01.23
Узнать размер файла


1-1105439083
Ega23
2005-01-11 13:24
2005.01.23
Breakpoint - мистика какая-то...