Link to home
Start Free TrialLog in
Avatar of Madmarlin
Madmarlin

asked on

Service Status Checking....


Hi,

I'm trying to check the current status of a service.

I've used this sample code from a previous question  logged on this site but when I change the service name from 'Alerter' to for example 'ClipBook' the returning value is given as an error (The Handle Is Invalid)
Any ideas as to why..

procedure TForm1.Button2Click(Sender: TObject);
var SC : integer;
  SHwnd : integer;
  ST : _Service_Status;
begin
 SC:=OpenSCManager(nil,'ServicesActive',GENERIC_READ);
 SHwnd:=OpenService(SC,'ClipBook',SERVICE_QUERY_STATUS);
  if not QueryServiceStatus(SHwnd,ST)
    then Listbox1.Items.Add('Error: ' + SysErrorMessage(GetLastError))
    else begin
   with listbox1.items do
case st.dwCurrentState of
SERVICE_START_PENDING    : Add('service start pending');
SERVICE_STOPPED          : Add('service stopped');
SERVICE_STOP_PENDING     : Add('service stop pending');
SERVICE_RUNNING          : Add('service started');
SERVICE_CONTINUE_PENDING : Add('service continue pending');
SERVICE_PAUSE_PENDING    : Add('service pause pending');
SERVICE_PAUSED           : Add('service paused');
end;
end;

end;



ASKER CERTIFIED SOLUTION
Avatar of TOndrej
TOndrej

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Madmarlin
Madmarlin

ASKER

i cant beleive that I was using the incorrect Name..

Thanks..
Madmarlin