zoukankan      html  css  js  c++  java
  • NT服务程序编写

    问题:我写了一个NT服务,我想在服务中添加一个窗体,如何操作? ( 积分:100, 回复:3, 阅读:45 )
    分类:多线程 ( 版主:g622, wjiachun )
    来自:想飞的男孩, 时间:2006-3-28 14:55:00, ID:3396265 [显示:小字体 | 大字体]

    1、大家如果说既然做了服务何必加窗体,服务有服务的好处,权限控制之后不能关闭等等,而窗体有窗体的必要,显示大量的信息就不是ShowMessage能够做到的,而程序中交互是必要的,参数设置等等!
    2、如果是服务调用Dll,在Dll中打开窗体,这个方法妖怪了点,暂时不考虑!
    3、如果是Forms.Application.CreateForm(TMainForm, MainForm);我试验过了,没有显示出来,可能我写的不正确!
    4、我也试验了,在服务启动的线程中,写入窗体的创建显示的代码,但是线程干活了,窗体没有显示!包括窗体的OnCreate也没有被调用!
    5、也试验了,在服务的OnStart中,写入窗体的创建显示的代码,服务崩了!
    6、顺,google和大富翁中任意关键字“NT 服务 窗体”的帖子我也都看了!
    7、知道的朋友望赐教!如果有思路,我也可以马上试验!
      

    来自:wxfdage, 时间:2006-3-28 17:10:09, ID:3396449
    服务里边好像不能弹出窗口的,可能是消息系统的问题。不一定非要把窗体做到服务里,只要作个程序和服务程序进行交互,同样能达到目的。  

    来自:amwfhv, 时间:2006-3-28 17:24:13, ID:3396464
    可以做在里面的要设置一下
    Interactive,当这个属性为True的时候,该服务程序就可以与桌面交互了.  

    来自:风铃夜思雨, 时间:2006-3-28 17:27:54, ID:3396473
    unit UnitMain;

    interface

    uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr;


    type
      (*----------------------------------------------------------------------------------*)
      TSvTProTime = class(TService)
        procedure ServiceStart(Sender: TService; var Started: Boolean);
        procedure ServiceStop(Sender: TService; var Stopped: Boolean);
        procedure ServiceExecute(Sender: TService);
        procedure ServiceContinue(Sender: TService; var Continued: Boolean);
      private
        procedure DisplayForm;
        procedure StartServer;
        procedure StopServer;
      public
        bDisplaying: Boolean;
        function GetServiceController: TServiceController; override;
      end;

    var
      SvTProTime: TSvTProTime;

    implementation

    {$R *.DFM}

    uses
      Unit1, Forms;

    var
      F: TForm;

    { methods }
    (*--------------------------------------------------------------------------------*)
    procedure TSvTProTime.DisplayForm;
    begin
      if bDisplaying then Exit;

      bDisplaying := True;
      F := TForm1.Create(nil);
      //F.Show;
    end;
    (*--------------------------------------------------------------------------------*)
    procedure TSvTProTime.StartServer;
    begin
      bDisplaying := False;
    end;
    (*--------------------------------------------------------------------------------*)
    procedure TSvTProTime.StopServer;
    begin
      if bDisplaying then F.Free;
    end;

    { events }
    (*--------------------------------------------------------------------------------*)
    procedure ServiceController(CtrlCode: DWord); stdcall;
    begin
      SvTProTime.Controller(CtrlCode);
    end;
    (*--------------------------------------------------------------------------------*)
    function TSvTProTime.GetServiceController: TServiceController;
    begin
      Result := ServiceController;
    end;
    (*--------------------------------------------------------------------------------*)
    procedure TSvTProTime.ServiceStart(Sender: TService; var Started: Boolean);
    begin
      Started := True;
      gbCanClose := False;
    end;
    (*--------------------------------------------------------------------------------*)
    procedure TSvTProTime.ServiceStop(Sender: TService; var Stopped: Boolean);
    begin
      ServiceThread.Terminate;
      Stopped := True;
      gbCanClose := True;
    end;
    (*--------------------------------------------------------------------------------*)
    procedure TSvTProTime.ServiceExecute(Sender: TService);
    begin
      StartServer;
      try
        while not Terminated do
        begin
          ServiceThread.ProcessRequests(False);
          Sleep(100);
          DisplayForm;
        end
      finally
        StopServer;
      end;
    end;

    procedure TSvTProTime.ServiceContinue(Sender: TService;
      var Continued: Boolean);
    begin
      Continued := True;
    end;

    end.
  • 相关阅读:
    python课堂练习
    Python爬虫学习笔记(九)——Selenium的使用
    Python爬虫学习笔记(八)——智高考数据爬取
    Python爬虫学习笔记(七)——Ajax
    Python爬虫学习笔记(六)——BeautifulSoup和pyquery的使用
    Python爬虫学习笔记(五)——XPath的使用
    Python爬虫学习笔记(四)——猫眼电影Top100
    Python爬虫学习笔记(三)——正则表达式
    Python爬虫学习笔记(二)——requests库的使用
    Python爬虫学习笔记(一)——urllib库的使用
  • 原文地址:https://www.cnblogs.com/fuyingke/p/361900.html
Copyright © 2011-2022 走看看