Access the answers to your technology questions today.
Subscribe Now
30-day free trial. Register in 60 seconds.
What Makes Experts Exchange Unique?
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.
Try it out and discover for yourself.
Subscribe Now
30-day free trial. Register in 60 seconds.
Join the Community
Give a Little. Get a Lot.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Join the Community
by: geobulPosted on 2001-11-20 at 03:42:11ID: 6644330
Hi Palli,
vice: string) : string; GENERIC_RE AD); r(sService ),STANDARD _RIGHTS_RE QUIRED+SER VICE_QUERY _STATUS); T) then begin or);
: TObject); 1.Text);
The following is a small app that shows the current status of a service, which name has been entered in the Edit box.
You can check the status of your service using Timer (in OnTimer event handler). Save the last status in a variable, compare it every time and when it has changed do something (show message, write log entry, etc.).
Regards, Geo
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses Winsvc;
function GetLocalServiceStatus(sSer
var
SC : integer;
SHwnd : integer;
ST : _Service_Status;
res : string;
begin
res := '';
SC:=OpenSCManager(nil,nil,
SHwnd:=OpenService(SC,PCha
if not QueryServiceStatus(SHwnd,S
res := 'Error: ' + SysErrorMessage(GetLastErr
end else begin
case st.dwCurrentState of
SERVICE_STOPPED : res := 'service stopped';
SERVICE_START_PENDING : res := 'service start pending';
SERVICE_STOP_PENDING : res := 'service stop pending';
SERVICE_RUNNING : res := 'service running';
SERVICE_CONTINUE_PENDING : res := 'service continue pending';
SERVICE_PAUSE_PENDING : res := 'service pause pending';
SERVICE_PAUSED : res := 'service paused';
end;
end;
result := res;
end;
procedure TForm1.Button1Click(Sender
begin
Label1.Caption := GetLocalServiceStatus(Edit
end;
end.