zoukankan      html  css  js  c++  java
  • Delphi 服务程序[2] TService 属性、事件

    Delphi 服务程序[2] TService 属性、事件

    1、TService属性:

    • AllowPause: //是否允许暂停
    • AllowStop: //是否允许停止
    • Dependencies: //设置该服务与其他服务的依赖关系
    • DisplayName: //在Windows服务管理器中显示的名称(注意:不是服务名)
    • ErrorSeverity //表明如果启动服务时遇到错误,如何处理
    • Name: //服务名称,使用/install参数安装时安装的服务名为此属性值  //在注册表中的HKEYU LOCALU MACHINESYSTEMCurrentControlSetServices下创建一个项。
    • Interactive: //是否要与桌面进行交互
    • StartType: //服务的启动方式
    • ServiceStartName: //设定用于启动服务的用户名
      • 服务以特定用户的身份运行,这意味着服务对不同事物(如文件夹)的访问权限与运行服务的帐户相同。许多服务作为“本地系统”运行,除非您在安装服务时指定特定的用户名。对于许多情况,“本地系统”就足够了,但是如果服务需要访问诸如网络驱动器/共享(通常受用户/密码保护)上的文件夹之类的内容,则可能需要指定一个已被授予访问网络共享权限的帐户。
    • Password: //用于设置口令。只适合于不使用LoaclSystem账号的服务
    • ServiceType   //服务的类型,可以设为:stWin32(Win32服务),stDevice(设备驱动程序)或stFileSystem(文件系统服务)
    • WaitHint   //服务等待控制命令或状态请求的时间。如果在规定的时间内没有响应,则SCM认为服务出错

    2、TService事件:

    • ServiceStart  //在该服务启动的时候调用OnStart事件,参数Started的默认为True,所以不用在该事件中再设置Started := True; 在此事件中如果判断某些条件不允许服务运行,则可以将Started置为False,这样服务将会不再启动。
    procedure TService1.ServiceStart(Sender: TService; var Started: Boolean);   
    • ServiceStop  //在该服务被停止的时候调用OnStop事件,Stopped的默认为True,在此事件中如果判断某些条件不允许服务停止则可将Stopped置为False来防止服务被停止。
    procedure TService1.ServiceStop(Sender: TService; var Stopped: Boolean);
    • ServiceExecute  //服务的主体执行部分,需要将服务的主要功能实现代码放在此事件中,此过程执行完毕后服务将会自动停止,所以一般在此事件中要写类似如下代码:
    procedure TService1.ServiceExecute(Sender: TService);
    begin
      while not Terminated do
      begin
        Sleep(10);
        ServiceThread.ProcessRequests(False);
      end;
    end;
    • ServicePause  //在服务被暂停时调用的事件,Paused的含义类似ServiceStart事件中的Started.
    procedure TService1.ServicePause(Sender: TService; var Paused: Boolean);
    • ServiceContinue  //服务被暂停后重新启动继续执行时调用的事件,Continued的含义类似ServiceStart事件中的Started
    procedure TService1.ServiceContinue(Sender: TService; var Continued: Boolean);
    

      

    创建时间:2021.01.21  更新时间:2021.01.22

    博客园 滔Roy https://www.cnblogs.com/guorongtao 希望内容对你所有帮助,谢谢!
  • 相关阅读:
    initramfs扫描磁盘前改变磁盘上电顺序
    “井号键”用英语怎么说?
    syslog,rsyslog and syslog-ng
    glob (programming) and spool (/var/spool)
    CentOS 6.5语言包裁剪
    C​P​U​_​C​S​t​a​t​e​_​P​S​t​a​t​e and then ACPI on Wiki
    we are experimenting with a new init system and it is fun
    linux init->upstart->systemd
    微信浏览器内建的WeixinJSBridge 实现“返回”操作
    npm i node-sass 报错&npm 镜像切换
  • 原文地址:https://www.cnblogs.com/guorongtao/p/14306151.html
Copyright © 2011-2022 走看看