ServiceList.pas

Top  Previous  Next

//****************************************************//

//                                                    //

//             Delphi Software Online                 //

//         internetes hetilap példaprogram            //

//           http://www.animare.hu/dso/               //

//               delphi@animare.hu                    //

//                                                    //

//             Animare Software © 2001                //

//              http://www.animare.hu                 //

//                                                    //

//****************************************************//

unit ServiceList;

 

interface

 

uses

Windows, Messages, SysUtils, Classes, Dsgnintf, Graphics, Controls, Forms, Dialogs, WinSvc;

 

type

TServiceType=(stAll, stWIN32, stDriver);

TServiceState=(ssAll, ssActive, ssInactive);

 

TServiceList = class(TComponent)

private

   FMachine: string;

   FServiceState: TServiceState;

   FServiceType: TServiceType;

   FItems: TStringList;

   procedure SetItems(const Value: TStringList);

   procedure SetMachine(const Value: string);

   procedure SetServiceState(const Value: TServiceState);

   procedure SetServiceType(const Value: TServiceType);

 

protected

 

public

   constructor Create(AOwner: TComponent); override;

   destructor Destroy; override;

   procedure Execute;

   procedure Clear;

 

published

   property Items: TStringList read FItems write SetItems;

   property Machine: string read FMachine write SetMachine;

   property ServiceType: TServiceType read FServiceType write SetServiceType;

   property ServiceState: TServiceState read FServiceState write SetServiceState;

 

end;

 

       TServiceListComponentEditor=class(TDefaultEditor)

       public

       procedure Edit; override;

   procedure ExecuteVerb(Index: Integer); override;

   function GetVerb(Index: Integer): string; override;

   function GetVerbCount: Integer; override;

 

end;

 

 

procedure Register;

 

implementation

 

procedure Register;

begin

RegisterComponents('DSO', [TServiceList]);

       RegisterComponentEditor(TServiceList, TServiceListComponentEditor);

end;

 

{ TServiceList }

 

procedure TServiceList.Clear;

begin

FItems.Clear;

end;

 

constructor TServiceList.Create(AOwner: TComponent);

begin

inherited;

FItems:=TStringList.Create;

end;

 

destructor TServiceList.Destroy;

begin

FItems.Free;

inherited;

end;

 

procedure TServiceList.Execute;

const

st: array[TServiceType] of DWORD=(SERVICE_TYPE_ALL, SERVICE_WIN32, SERVICE_DRIVER);

ss: array[TServiceState] of DWORD=(SERVICE_STATE_ALL, SERVICE_ACTIVE, SERVICE_INACTIVE);

type

TESS=array[0..1023] of TEnumServiceStatus;

PESS=^TESS;

var

i: integer;

handle: SC_HANDLE;

dwBytesNeeded, dwServicesReturned, dwResumeHandle: DWORD;

ess: PESS;

begin

handle:=OpenSCManager(PChar(FMachine), nil, SC_MANAGER_ALL_ACCESS);

if handle>0 then begin

   FItems.Clear;

   dwResumeHandle:=0;

   New(ess);

   EnumServicesStatus(handle, st[FServiceType], ss[FServiceState], ess^[0], SizeOf(ess^), dwBytesNeeded, dwServicesReturned, dwResumeHandle);

   for i:=0 to dwServicesReturned-1 do begin

     FItems.Add(ess^[i].lpDisplayName);

   end;

   Dispose(ess);

   CloseServiceHandle(handle);

   FItems.Sort;

end;

end;

 

procedure TServiceList.SetItems(const Value: TStringList);

begin

end;

 

procedure TServiceList.SetMachine(const Value: string);

begin

FMachine := Value;

end;

 

procedure TServiceList.SetServiceState(const Value: TServiceState);

begin

FServiceState := Value;

end;

 

procedure TServiceList.SetServiceType(const Value: TServiceType);

begin

FServiceType := Value;

end;

 

{ TServiceListComponentEditor }

 

procedure TServiceListComponentEditor.Edit;

begin

with (Component as TServiceList) do begin

   Execute;

end;

end;

 

procedure TServiceListComponentEditor.ExecuteVerb(Index: Integer);

begin

       case index of

         0: Edit;

         1: (Component as TServiceList).Clear;

end;

end;

 

function TServiceListComponentEditor.GetVerb(Index: Integer): string;

begin

       case index of

         0: result:='Execute';

         1: result:='Clear';

end;

end;

 

function TServiceListComponentEditor.GetVerbCount: Integer;

begin

result:=2;

end;

 

end.

 

 

pl.