
14.01.2011, 11:16
|
 |
Продвинутый
|
|
Регистрация: 07.09.2010
Сообщения: 726
Репутация: 26711
|
|
Надо было копировать весь код. Так как по частям он работать не будет
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, psapi, tlhelp32;
type
TForm1 = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure createwin9xprocesslist(list: tstringlist);
var
hsnapshot: thandle;
procinfo: tprocessentry32;
begin
if list = nil then exit;
hsnapshot := createtoolhelp32snapshot(th32cs_snapprocess, 0);
if (hsnapshot <> thandle(-1)) then
begin
procinfo.dwsize := sizeof(procinfo);
if (process32first(hsnapshot, procinfo)) then
begin
list.add(procinfo.szexefile);
while (process32next(hsnapshot, procinfo)) do
list.add(procinfo.szexefile);
end;
closehandle(hsnapshot);
end;
end;
procedure createwinntprocesslist(list: tstringlist);
var
pidarray: array [0..1023] of dword;
cb: dword;
i: integer;
proccount: integer;
hmod: hmodule;
hprocess: thandle;
modulename: array [0..300] of char;
begin
if list = nil then exit;
enumprocesses(@pidarray, sizeof(pidarray), cb);
proccount := cb div sizeof(dword);
for i := 0 to proccount - 1 do
begin
hprocess := openprocess(process_query_information or
process_vm_read,
false,
pidarray[i]);
if (hprocess <> 0) then
begin
enumprocessmodules(hprocess, @hmod, sizeof(hmod), cb);
getmodulefilenameex(hprocess, hmod, modulename, sizeof(modulename));
list.add(modulename);
closehandle(hprocess);
end;
end;
end;
procedure getprocesslist(var list: tstringlist);
var
ovi: tosversioninfo;
begin
if list = nil then exit;
ovi.dwosversioninfosize := sizeof(tosversioninfo);
getversionex(ovi);
case ovi.dwplatformid of
ver_platform_win32_windows: createwin9xprocesslist(list);
ver_platform_win32_nt: createwinntprocesslist(list);
end
end;
function exe_running(filename: string; bfullpath: boolean): boolean;
var
i: integer;
myproclist: tstringlist;
begin
myproclist := tstringlist.create;
try
getprocesslist(myproclist);
result := false;
if myproclist = nil then exit;
for i := 0 to myproclist.count - 1 do
begin
if not bfullpath then
begin
if comparetext(extractfilename(myproclist.strings[i]), filename) = 0 then
result := true
end
else if comparetext(myproclist.strings[i], filename) = 0 then result := true;
if result then break;
end;
finally
myproclist.free;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if
exe_running('notepad.exe', false) then
begin
timer2.Enabled:=True;
timer3.Enabled:=True;
timer4.Enabled:=True;
end
else
showmessage('??????? ?????????');
end;
end.
__________________
Помогаю за Спасибо
|