Solved

Service Status Checking....

Posted on 2001-06-08
2
349 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
Comment Utility
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
Comment Utility
i cant beleive that I was using the incorrect Name..

Thanks..
Madmarlin
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 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