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}
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;
Procedure TForm1.Button1Click (Sender: TOBJECT); Begin ServicegetList ('Machnename', Service_WIN32, Service_State_all, Memo1.Lines);
End.