Solved

Service Status Checking....

Posted on 2001-06-08
2
379 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 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