Solved

Service Status Checking....

Posted on 2001-06-08
2
357 Views
Last Modified: 2006-11-17

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;



0
Comment
Question by:Madmarlin
2 Comments
 
LVL 8

Accepted Solution

by:
TOndrej earned 50 total points
ID: 6167431
Most probably you are using an incorrect name of the service. Note that Name of a service can be different from DisplayName (shown in Control Panel).

sc query shows:

SERVICE_NAME: ClipSrv
DISPLAY_NAME: ClipBook Server
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE,NOT_PAUSABLE,IGNORES_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0
0
 
LVL 1

Author Comment

by:Madmarlin
ID: 6167504
i cant beleive that I was using the incorrect Name..

Thanks..
Madmarlin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now