Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "WinAPI";
Текущий архив: 2005.08.21;
Скачать: [xml.tar.bz2];

Вниз

Менеджер процессов   Найти похожие ветки 

 
SpyBoy ©   (2005-07-03 11:48) [0]

Можете привести пример простенького менеджера процессов:
В ЛистБоксе отображаются все процессы.


 
ferr ©   (2005-07-03 11:53) [1]

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;

© DelphiWorld


 
SpyBoy ©   (2005-07-03 12:37) [2]

Но так показываются лишь приложения(Названия окон процессов), а надо , чтобы Все процессы, включая и SVHOST,Lsass


 
Alexander Panov ©   (2005-07-03 12:38) [3]

ЧТо ты понимаешь под понятием "менеджер процессов"?


 
lookin ©   (2005-07-03 12:43) [4]

Только вы уж сами тут разбирайтесь...

unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
 tlhelp32, StdCtrls, ComCtrls, ExtCtrls, Menus, Tabnotbk;

type
 TForm1 = class(TForm)
   Timer1: TTimer;
   PopupMenu1: TPopupMenu;
   Terminateprocess1: TMenuItem;
   TabbedNotebook1: TTabbedNotebook;
   ListView1: TListView;
   ListView2: TListView;
   PopupMenu2: TPopupMenu;
   Activateapplication1: TMenuItem;
   Closeapplication1: TMenuItem;
   Gettext1: TMenuItem;
   procedure FormShow(Sender: TObject);
   procedure Timer1Timer(Sender: TObject);
   procedure Terminateprocess1Click(Sender: TObject);
   procedure ListView1MouseDown(Sender: TObject; Button: TMouseButton;
     Shift: TShiftState; X, Y: Integer);
   procedure Activateapplication1Click(Sender: TObject);
   procedure ListView2MouseDown(Sender: TObject; Button: TMouseButton;
     Shift: TShiftState; X, Y: Integer);
   procedure Closeapplication1Click(Sender: TObject);
   procedure Gettext1Click(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 end;
 procedure StopProcess(ProcessID,ThreadID: dword);
 procedure SortWindow;
procedure SimulateKeystroke(Key : byte; extra : DWORD);

var
 Form1: TForm1;
 selecteditem: TListItem;
 h,h1: hwnd;
 p: array [0..255] of char;
 no,ist: boolean;
 s: string;
 equ: integer;

implementation

{$R *.DFM}

procedure TForm1.FormShow(Sender: TObject);
var pe32: PROCESSENTRY32;
   num,i: integer;
   hd: hwnd;
   d: dword;
   hl: hlocal;
begin
 selecteditem:=nil;
 hd:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
 Process32First(hd,pe32); num:=0;
 while Process32Next(hd,pe32) do begin
 if num=0 then ListView1.Items.Clear; ListView1.Items.Add;
 ListView1.Items.Item[num].Caption:=pe32.szExeFile;
 ListView1.Items.Item[num].SubItems.Insert(0,IntToStr(pe32.pcPriClassBase));
 ListView1.Items.Item[num].SubItems.Insert(1,IntToStr(pe32.cntUsage));
 ListView1.Items.Item[num].SubItems.Insert(2,IntToStr(pe32.th32ProcessID));
 ListView1.Items.Item[num].SubItems.Insert(3,IntToStr(pe32.th32DefaultHeapID));
 ListView1.Items.Item[num].SubItems.Insert(4,IntToStr(pe32.cntThreads));
 ListView1.Items.Item[num].SubItems.Insert(5,IntToStr(pe32.th32ParentProcessID));
 ListView1.Items.Item[num].SubItems.Insert(6,IntToStr(pe32.th32ModuleID));
 num:=num+1; end;
 h:=Form1.Handle; h1:=h; no:=false;
 while no=false do begin ist:=false; h:=GetNextWindow(h,GW_HWNDNEXT);
 if h=0 then no:=true; GetWindowText(h,p,255); s:=StrPas(p);
 for i:=0 to ListView2.Items.Count-1 do
 if s=ListView2.Items.Item[i].Caption then begin ist:=true; break; end;
 if (s<>"") and (ist=false) then begin ListView2.Items.Add;
 ListView2.Items.Item[ListView2.Items.Count-1].Caption:=s;
 end; end; h:=h1; no:=false;
 while no=false do begin ist:=false; h:=GetNextWindow(h,GW_HWNDPREV);
 if h=0 then no:=true; GetWindowText(h,p,255); s:=StrPas(p);
 for i:=0 to ListView2.Items.Count-1 do
 if s=ListView2.Items.Item[i].Caption then begin ist:=true; break; end;
 if (s<>"") and (ist=false) then begin ListView2.Items.Add;
 ListView2.Items.Item[ListView2.Items.Count-1].Caption:=s;
 end; end; Timer1.Enabled:=true;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var pe32: PROCESSENTRY32;
   num,i: integer;
   hd: hwnd;
   str: array of string;
begin
//  ListView2.Items.Clear;
 hd:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
 Process32First(hd,pe32); num:=0;
 while Process32Next(hd,pe32) do begin
 if ListView1.Items.Count=num then ListView1.Items.Add;
 ListView1.Items.Item[num].Caption:=pe32.szExeFile;
 ListView1.Items.Item[num].SubItems.Insert(0,IntToStr(pe32.pcPriClassBase));
 ListView1.Items.Item[num].SubItems.Insert(1,IntToStr(pe32.cntUsage));
 ListView1.Items.Item[num].SubItems.Insert(2,IntToStr(pe32.th32ProcessID));
 ListView1.Items.Item[num].SubItems.Insert(3,IntToStr(pe32.th32DefaultHeapID));
 ListView1.Items.Item[num].SubItems.Insert(4,IntToStr(pe32.cntThreads));
 ListView1.Items.Item[num].SubItems.Insert(5,IntToStr(pe32.th32ParentProcessID));
 ListView1.Items.Item[num].SubItems.Insert(6,IntToStr(pe32.th32ModuleID));
 Inc(num); end;
 if num<ListView1.Items.Count then while ListView1.Items.Count<>num do
 ListView1.Items.Item[ListView1.Items.Count-1].Delete;

{  num:=0; h:=Form1.Handle; h1:=h; no:=false;
 while no=false do begin h:=GetNextWindow(h,GW_HWNDNEXT);
 if h<>0 then begin GetWindowText(h,p,255); s:=StrPas(p);
 if s<>"" then begin SetLength(str,num+1); str[num]:=s; Inc(num); end; end
 else no:=true; end; h:=h1; no:=false;
 while no=false do begin h:=GetNextWindow(h,GW_HWNDPREV);
 if h<>0 then begin GetWindowText(h,p,255); s:=StrPas(p);
 {if s<>"" then begin SetLength(str,num+1); str[num]:=s; Inc(num); end; end
 else no:=true; end;

{  if Length(str)<ListView2.Items.Count then
 while ListView2.Items.Count<>Length(str) do
 ListView2.Items.Item[ListView2.Items.Count-1].Delete;
 for i:=0 to Length(str)-1 do begin
 if i<=ListView2.Items.Count-1 then ListView2.Items.Item[i].Caption:=str[i];
 if i>ListView2.Items.Count-1 then begin ListView2.Items.Add;
 ListView2.Items.Item[ListView2.Items.Count-1].Caption:=str[i]; end; end;
}end;

procedure StopProcess(ProcessID,ThreadID: dword);
var prochandle,thrdhandle: THandle;
   www: dword;
begin
 if DebugActiveProcess(ProcessID) then begin
 prochandle:=OpenProcess(PROCESS_ALL_ACCESS,true,ProcessID);
 if prochandle<>0 then
 if TerminateProcess(prochandle,www)<>false then
 showmessage("Process "+selecteditem.Caption+" is successfully terminated");
//  if TerminateThread(prochandle,www)<>false then showmessage("Terminated");
 CloseHandle(prochandle); end;
end;

to be continued...


 
lookin ©   (2005-07-03 12:43) [5]

procedure TForm1.Terminateprocess1Click(Sender: TObject);
var pe32: PROCESSENTRY32;
   te32: THREADENTRY32;
   num: integer;
   procID,thrdID,www: dword;
   ath: dword;
   hd: hwnd;
   find,findthread: boolean;
   procname: Ansistring;
   th: thandle;
   prochandle,thrdhandle: THandle;
   px: PChar;
   s: string;
begin
 Timer1.Enabled:=false;
 find:=false; findthread:=false;
 hd:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
 Process32First(hd,pe32); num:=0;
 while (Process32Next(hd,pe32)) and (find=false) do begin
 procname:=pe32.szExeFile;
 if procname=selecteditem.Caption then begin
 prochandle:=OpenProcess(PROCESS_ALL_ACCESS,true,pe32.th32ProcessID);

{  if prochandle<>0 then begin
   px:=getcommandline();
 s:=StrPas(px); showmessage(s); end;
}

 procID:=pe32.th32ProcessID; Thread32First(hd,te32);
 while (Thread32Next(hd,te32)) and (findthread=false) do
 if te32.th32OwnerProcessID=procID then begin
 thrdID:=te32.th32ThreadID; findthread:=true; end;

 find:=true; end; num:=num+1; end;
 if find then StopProcess(procID,thrdID);
 Timer1.Enabled:=true;
end;

procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
 Shift: TShiftState; X, Y: Integer);
begin
 if Button=mbRight then begin selecteditem:=ListView1.GetItemAt(X,Y);
 PopupMenu1.Popup(X+ListView1.ClientOrigin.x,Y+ListView1.ClientOrigin.y); end;
end;

procedure TForm1.Activateapplication1Click(Sender: TObject);
var tl: string;
begin
 tl:=selecteditem.Caption; h:=Form1.Handle; h1:=h; no:=false;
 while no=false do begin h:=GetNextWindow(h,GW_HWNDNEXT);
 if h=0 then no:=true; GetWindowText(h,p,255); s:=StrPas(p);
 if s=tl then begin ShowWindow(h,SW_RESTORE); SetForegroundWindow(h);
 RedrawWindow(h,0,0,RDW_VALIDATE and RDW_UPDATENOW and RDW_ALLCHILDREN);
 no:=true; break; end; end;
 if no=false then begin h:=h1;
 while no=false do begin h:=GetNextWindow(h,GW_HWNDPREV);
 if h=0 then no:=true; GetWindowText(h,p,255); s:=StrPas(p);
 if s=tl then begin ShowWindow(h,SW_RESTORE); SetForegroundWindow(h);
 RedrawWindow(h,0,0,RDW_VALIDATE and RDW_UPDATENOW and RDW_ALLCHILDREN);
 no:=true; break; end; end; end;
end;

procedure TForm1.ListView2MouseDown(Sender: TObject; Button: TMouseButton;
 Shift: TShiftState; X, Y: Integer);
begin
 if Button=mbRight then begin
 selecteditem:=ListView2.GetItemAt(X,Y);
 PopupMenu2.Popup(X+ListView2.ClientOrigin.x,Y+ListView2.ClientOrigin.y); end;
end;

procedure TForm1.Closeapplication1Click(Sender: TObject);
var tl: string;
begin
 tl:=selecteditem.Caption; h:=Form1.Handle; h1:=h; no:=false;
 while no=false do begin h:=GetNextWindow(h,GW_HWNDNEXT);
 if h=0 then no:=true; GetWindowText(h,p,255); s:=StrPas(p);
 if s=tl then begin CloseWindow(h); no:=true; break; end; end;
 if no=false then begin h:=h1;
 while no=false do begin h:=GetNextWindow(h,GW_HWNDPREV);
 if h=0 then no:=true; GetWindowText(h,p,255); s:=StrPas(p);
 if s=tl then begin CloseWindow(h); no:=true; break; end; end; end;
end;

procedure SortWindow;
begin
//
end;

procedure TForm1.Gettext1Click(Sender: TObject);
var tl: string;
   hh: hWnd;
   px: PChar;
   m: MSG;
begin
 tl:=selecteditem.Caption;
 h:=Form1.Handle; h1:=h; no:=false;
 while no=false do begin h:=GetNextWindow(h,GW_HWNDNEXT);
 if h=0 then no:=true; GetWindowText(h,p,255); s:=StrPas(p);
 if s=tl then begin
 setforegroundwindow(h);
 simulatekeystroke(ord("A"),0);
 break; end; end;
 if no=false then begin h:=h1;
 while no=false do begin h:=GetNextWindow(h,GW_HWNDPREV);
 if h=0 then no:=true; GetWindowText(h,p,255); s:=StrPas(p);
 if s=tl then begin
 setforegroundwindow(h);
 simulatekeystroke(ord("A"),0);
 break; end; end; end;
end;

procedure SimulateKeystroke(Key : byte; extra : DWORD);
begin
 keybd_event(Key,extra,0,0);
 keybd_event(Key,extra,KEYEVENTF_KEYUP,0);
end;

end.


 
SpyBoy ©   (2005-07-03 12:46) [6]

Спасибо, а откуда взяли?


 
Игорь Шевченко ©   (2005-07-04 10:33) [7]

http://www.schevchenko.net.ru/SRC/QuerySystemInformation_60.zip



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

Форум: "WinAPI";
Текущий архив: 2005.08.21;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.49 MB
Время: 0.034 c
3-1121071009
bendela
2005-07-11 12:36
2005.08.21
ado+ms Access редактирование записи


3-1121234219
leonidus
2005-07-13 09:56
2005.08.21
ADO с провайдером Microsoft.Jet.OLEDB.4.0 не хочет делать INSERT


1-1122823023
TStas
2005-07-31 19:17
2005.08.21
Как делят потоки стек?


14-1122647124
oldman
2005-07-29 18:25
2005.08.21
Проблемы с несчастным SP2.


1-1123082671
Nikus
2005-08-03 19:24
2005.08.21
Как быть





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский