Delphi Can

Orjinalini görmek için tıklayınız: Windows Hizmet Listesi
Şu anda (Arşiv) modunu görüntülemektesiniz. Orjinal Sürümü Görüntüle internal link
Merhaba arkadaşlar,

Hizmetler deki Servis listesini nasıl çekebilirim?

unit Unit1;

interface

uses
 Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
 Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
 TForm1 = class(TForm)
   ListBox1: TListBox;
   Button1: TButton;
   procedure Button1Click(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 end;





var
 Form1: TForm1;

implementation

{$R *.dfm}

uses WinSvc;

{$IFDEF CONDITIONALEXPRESSIONS}
 {$IF CompilerVersion >= 34}
   {$DEFINE lpServices_Param_Is_Pointer}
 {$IFEND}
{$ENDIF}

function ServiceGetList(
 const sMachine : string;
 dwServiceType,
 dwServiceState : DWord;
 slServicesList : TStrings )
 : Boolean;
var
 j : integer;
 schm : SC_Handle;
 nBytesNeeded,
 nServices,
 nResumeHandle : DWord;
 buffer : array of Byte;
 ssa, ss : PEnumServiceStatus;
begin
 Result := False;

 schm := OpenSCManager(
   PChar(sMachine),
   nil,
   SC_MANAGER_CONNECT or SC_MANAGER_ENUMERATE_SERVICE);

 if (schm <> 0) then
 try
   nResumeHandle := 0;
   if not EnumServicesStatus(
     schm,
     dwServiceType,
     dwServiceState,
     {$IFDEF lpServices_Param_Is_Pointer}nil{$ELSE}PEnumServiceStatus(nil)^{$ENDIF},
     0,
     nBytesNeeded,
     nServices,
     nResumeHandle) then
   begin
     if (GetLastError() <> ERROR_INSUFFICIENT_BUFFER) and (GetLastError() <> ERROR_MORE_DATA) then
     begin
       Exit;
     end;
     SetLength(buffer, nBytesNeeded);
     ssa := PEnumServiceStatus(buffer);
     if not EnumServicesStatus(
       schm,
       dwServiceType,
       dwServiceState,
       ssa{$IFNDEF lpServices_Param_Is_Pointer}^{$ENDIF},
       Length(buffer),
       nBytesNeeded,
       nServices,
       nResumeHandle) then
     begin
       Exit;
     end;
   end;
   if (nServices > 0) then
   begin
     ss := ssa;
     for j := 0 to nServices-1 do
     begin
       slServicesList.Add(ss.lpDisplayName);
       Inc(ss);
     end;
   end;
 finally
   CloseServiceHandle(schm);
 end;
 Result := True;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
ServiceGetList( '',
 SERVICE_WIN32,
 SERVICE_STATE_ALL,
 ListBox1.Items );
end;

end.


bu kodlarla geliyormus.