Solved

Service Status Checking....

Posted on 2001-06-08
2
375 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adoquery sql  left join does not work 25 104
Typecasting TBytes to Integer in Delphi XE8 2 33
Firemonkey Listview item popup menu ? 1 26
Using MMsystem To change audio input 1 14
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

740 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