yewnix
asked on
Process List in a Service Application
I'm trying to develop a service application that watches the processes that are currently running.
Everything I've tried so far with EnumWindows etc is not working inside the service application.
Could someone please give me an example of how to get the current list of running process into say a TStringList
within a Service Application ?
Everything I've tried so far with EnumWindows etc is not working inside the service application.
Could someone please give me an example of how to get the current list of running process into say a TStringList
within a Service Application ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
as you wish,
with WMI you can execute notification query which will trigger each time specified process is spawned so you dont need to loop and check for notepad or any other process
anyway thanks for points.
ziolko.
with WMI you can execute notification query which will trigger each time specified process is spawned so you dont need to loop and check for notepad or any other process
anyway thanks for points.
ziolko.
ASKER
I have figured it out. Here is my findings.
procedure TService3.ServiceExecute(S
var
I: Integer;
Snapshot: THandle;
processhandle : THandle;
PE: TProcessEntry32;
begin
while not Terminated do
begin
Snapshot := CreateToolhelp32Snapshot(T
if (Snapshot = DWORD(-1)) then
Exit;
PE.dwSize := SizeOf(TProcessEntry32);
if Process32First(Snapshot, PE) then
repeat
if Pe.szExeFile = 'notepad.exe' then
begin
ProcessHandle := OpenProcess(PROCESS_TERMIN
TerminateProcess(ProcessHa
CloseHandle(ProcessHandle)
end;
until not Process32Next(Snapshot, PE);
CloseHandle (Snapshot);
sleep(200);
ServiceThread.ProcessReque
end;
end;
procedure TService3.ServiceStop(Send
begin
ServiceThread.Terminate;
end;
--------------------------
This will close notepad.exe anytime its started.
I appreciate your post so I will honor you the points as I will mostly likely use those in the future.
Thanks.