枚举NT系统服务

Delphi 专栏收录该内容
3 篇文章 0 订阅

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.

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值