Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

Checking services and processes

Hi Experts,

I need to check when a particular process or service is running.
Is there any way to do this in delphi 7
Thx
0
alpires
Asked:
alpires
2 Solutions
 
SmukecCommented:
0
 
alpiresAuthor Commented:
Smukec, and how to know if a process is running ?
0
 
epasquierCommented:
This could find you a process which executable starts with a given string. Works with services also as they are process like others. You can also filter with others fields of Process32First/Next answer if you need to.

OracleIsRunning:=SearchProcessID('oracle.exe')>0;
Function SearchProcessID(Process:String):Integer;
var
 H: THandle;
 pe: tlhelp32.TProcessEntry32;
 B: Boolean;
 Str:String;
begin
 Result:=0;
 Process:=UpperCase(Process);
 H:= tlhelp32.CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
 try
  pe.dwSize:= SizeOf(pe);
  B:= tlhelp32.Process32First(H, pe);
  while B do
   begin
    Str:=UpperCase(pe.szExeFile);
    if Copy(Str,1,Length(Process))=Process Then
     begin
      B:=False;
      Result:=pe.th32ProcessId;
     end Else B:= tlhelp32.Process32Next(H, pe);
   end;
 finally
  CloseHandle(H);
 end;
end;

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now