unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Winsvc, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function ServiceGetList(sMachine: string; dwServiceType,
dwServiceState: DWord; slServicesList: TStrings): boolean;
var
j : integer;
schm: SC_Handle;
nBytesNeeded,
nServices,
nResumeHandle: DWord;
ServiceStatusRecs: array[0..511] of TEnumServiceStatus;
begin
Result := false;
schm := OpenSCManager(PChar(sMachine), Nil, SC_MANAGER_ALL_ACCESS);
try
if (schm = 0) then Exit;
nResumeHandle := 0;
while True do begin
EnumServicesStatus(schm, dwServiceType, dwServiceState, ServiceStatusRecs[0], sizeof(ServiceStatusRecs), nBytesNeeded, nServices, nResumeHandle);
for j := 0 to nServices-1 do begin
slServicesList.Add(ServiceStatusRecs[j].lpDisplayName);
end;
if nBytesNeeded = 0 then Break;
end;
Result := true;
finally
if schm > 0 then
CloseServiceHandle(schm);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ServiceGetList('MachineName',SERVICE_WIN32,SERVICE_STATE_ALL,memo1.Lines );
end;
end.