rtcservice.pas

来自「Delphi快速开发Web Server」· PAS 代码 · 共 62 行

PAS
62
字号
{ @exclude }
unit rtcService;

{$include rtcDefs.inc}

interface

uses
  Windows,
  WinSvc,
  SysUtils;

function IsServiceStarting(const ServiceName:string):boolean;

function IsDesktopMode(const ServiceName:string):boolean;

function IsMiniMode:boolean;

implementation

function IsServiceStarting(const ServiceName:string): Boolean;
  var
    Svc: Integer;
    SvcMgr: Integer;
    ServSt: TServiceStatus;
  begin
  Result := False;
  SvcMgr := OpenSCManager(nil, nil, SC_MANAGER_CONNECT);
  if SvcMgr = 0 then Exit;
  try
    Svc := OpenService (SvcMgr, PChar(ServiceName), SERVICE_QUERY_STATUS);
    if Svc = 0 then Exit;
    try
      if not QueryServiceStatus (Svc, ServSt) then Exit;
      Result := (ServSt.dwCurrentState = SERVICE_START_PENDING);
    finally
      CloseServiceHandle(Svc);
      end;
  finally
    CloseServiceHandle(SvcMgr);
    end;
  end;

function IsDesktopMode(const ServiceName:string):boolean;
  begin
  if (Win32Platform <> VER_PLATFORM_WIN32_NT) then
    Result := True
  else
    begin
    Result := not FindCmdLineSwitch('INSTALL', ['-', '/'], True) and
              not FindCmdLineSwitch('UNINSTALL', ['-', '/'], True) and
              not IsServiceStarting(ServiceName);
    end;
  end;

function IsMiniMode:boolean;
  begin
  Result:=FindCmdLineSwitch('M',['-','/'],True);
  end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?