delphi->new->service开始一个服务程序框架,设置service属性,对afterinstall,beforeinstall,on creaet,ondestory,onpause,onstart,onstop进行编程.
注意:不要有窗口界面

解决方案 »

  1.   

    在winNt下怎么做在win2k就怎么做,一样的。
      

  2.   

      不是,大家不会,只是做一个服务,而且要调试成功,比较麻烦,其实delphi作的服务已经够简单了,自己试试吧,不要光问不炼,
    只等现成的,
       你只要注意,(onstart,onshutdown....等)几个事件的处理,以及服务线程的可调度设计,就行了,   还有,可以有界面的,大概是在onCreate事件里处理。多动动手,delphi里有简单的例子的!
      

  3.   

    我做过,但用vc做的,delphi中的那个太简单,缺少用户自定义控制方法,对空闲触发事件和紧急触发事件也没有例子,而vc中有许多完善的例子,你可以把它改写成delphi的。比如,要实现空闲时每十分钟执行一次任务,当用户定义的紧急事件到来时,立即执行任务,怎么办?记得在msdn中有几个例子。
      

  4.   

    最完整的例子是那个SCKTSVRV的源程序
      

  5.   

    Delphi有个VCL程序,那里面你可参考一下。
    \delphi5\source\vcl\scktsrvr.dpr
    也好像就是TSocketService类中的OnStart, OnShutDown这两个事件,其它的事就像Delphi程序一样用吧
      

  6.   

    File菜单->New下选择Service或Service Application  建议选择使用Service Application建立服务程序。编译后的执行文件在开始菜单的"运行"中使用以下方法加载和卸载服务:
    d:\service_name.exe /install  //加载服务程序
    d:\service_name.exe /uninstall  //卸载服务程序加载服务后可以在控制面板->管理工具的"服务"中找到该服务。delphi5编写出的服务程序在winNt和win2k中通用。另外在uses WinSvc;, 在WinSvc中有很多关于控制服务的函数。很详细了,给分吧 
      

  7.   

    看看先。//工程文件
    program Project1;uses
      Windows, SvcMgr, WinSvc, Forms, SysUtils,
      Unit1 in 'Unit1.pas' {Service1: TService},
      Unit2 in 'Unit2.pas' {Form2};{$R *.RES}const
      SServiceName = 'MyApplication';
    {是否install, or uninstall}
    function Installing: Boolean;
    begin
      Result := FindCmdLineSwitch('INSTALL',['-','\','/'], True) or
                FindCmdLineSwitch('UNINSTALL',['-','\','/'], True);
    end;function StartService: Boolean;
    var
      Mgr, Svc: Integer;
    begin
      Result := False;
      Mgr := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS); 
      if Mgr <> 0 then
      begin  //这函数就像在“服务”中启动某个服务一样的作用。
        Svc := OpenService(Mgr, PChar(SServiceName), SERVICE_ALL_ACCESS);
        Result := Svc <> 0;
        CloseServiceHandle(Mgr);
      end;
    end;begin
      if not Installing then
      begin{如果有本程序实例,退出}
        CreateMutex(nil, True, 'MyService');
        if GetLastError = ERROR_ALREADY_EXISTS then
        begin
          MessageBox(0, 'Already Running', 'Error', MB_ICONERROR);
          Halt;
        end;
      end;
      //如果是出现在“服务”中而且是自动启动,则是下面情况
      if Installing and StartService then
      begin
        SvcMgr.Application.Initialize;
        Service1 := TService1.CreateNew(SvcMgr.Application, 0);
        SvcMgr.Application.CreateForm(TForm2, Form2);
        SvcMgr.Application.Run;
      end
      else{否则是以Explorer, 双击来启动本程序,则是这种情况}
      begin
        Forms.Application.Initialize;
        Application.CreateForm(TForm2, Form2);
        Form2.Initialize;
        Application.Run;
      end;
    end.//TService服务单元(menus->new->Service Application)
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs;type
      TService1 = class(TService)
        procedure ServiceStart(Sender: TService; var Started: Boolean);
        procedure ServiceStop(Sender: TService; var Stopped: Boolean);
      private
        { Private declarations }
      public
        function GetServiceController: TServiceController; override;
        { Public declarations }
      end;var
      Service1: TService1;implementationuses Unit2;
    {$R *.DFM}procedure ServiceController(CtrlCode: DWord); stdcall;
    begin
      Service1.Controller(CtrlCode);
    end;function TService1.GetServiceController: TServiceController;
    begin
      Result := ServiceController;
    end;procedure TService1.ServiceStart(Sender: TService; var Started: Boolean);
    begin {Tell Form2 进行初始工作}
      PostMessage(Form2.Handle, WM_Initialize, 0, 0);
    end;procedure TService1.ServiceStop(Sender: TService; var Stopped: Boolean);
    begin //退出
      PostMessage(Form2.Handle, WM_Quit, 0, 0);
    end;end.//TService只是做启动用,真正作用的在你的Form实例中,在你的Form中作你的服务。
    //TForm2
    unit Unit2;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;const
      WM_Initialize = WM_User + 100;type
      TForm2 = class(TForm)
      private
        { Private declarations }
        procedure WMStart(var Message: TMessage); message WM_Initialize;
      public
        procedure Initialize;
        { Public declarations }
      end;var
      Form2: TForm2;implementation{$R *.DFM}{ TForm2 }procedure TForm2.Initialize;
    begin
      //Initialize Form all object
    end;//如果是启动“服务”中启动的,这里会有用的。
    procedure TForm2.WMStart(var Message: TMessage);
    begin
      Initialize;
    end;//然后再写其它的服务类或什么的,写在Initialize中
    end.写的比较简单,都是从Scktsrvr.dpr copy过来,你怎么不去看看。
      

  8.   

    To:Tod(菜鸟) 
      我前一个月就发过这个贴子了,还被版主臭骂一顿,
      到一前去找找。
      Crob讲的很明确了。