Write a template for a service program (many can be found online)

Source: Internet
Author: User

//unit Untservice;InterfaceusesWindows, Messages, Sysutils, Classes, Graphics, Controls, Svcmgr, Dialogs, DB, Adodb,registry,activex;typeTService2=class(TService) con1:tadoconnection; procedureServiceexecute (Sender:tservice); procedureServiceafterinstall (Sender:tservice); procedureServicecontinue (Sender:tservice;varContinued:boolean); procedureServicestart (Sender:tservice;varStarted:boolean); procedureServicepause (Sender:tservice;varPaused:boolean); Private    {Private Declarations}   Public    functionGetservicecontroller:tservicecontroller;Override; {Public Declarations}  End;varService2:tservice2;Implementation{$R *. DFM}procedureServiceController (Ctrlcode:dword);stdcall;beginService2.controller (ctrlcode);End;functionTService2.GetServiceController:TServiceController;beginResult:=ServiceController;End;procedureTservice2.serviceexecute (sender:tservice);begin  while  notTerminated Do  beginservicethread.processrequests (True); //Do some thing;    //here VCL creates a thread and implements a message pump to receive messages in the thread    //You can add the loop detection event here.Sleep ( -); End;End;procedureTservice2.serviceafterinstall (sender:tservice);varRegistry:tregistry; key:string;beginRegistry:= Tregistry.Create; TryRegistry.rootkey:=HKEY_LOCAL_MACHINE; Key:='system/currentcontrolset/services/'+Name; ifRegistry.keyexists (Key) Then    beginRegistry.openkey (key, True); Registry.writestring ('Description','xxxxxxxxxxxxx');    Registry.closekey; End; finallyRegistry.free; End;End;procedureTservice2.servicecontinue (Sender:tservice; varContinued:boolean);begincontinued:=True;End;procedureTservice2.servicestart (Sender:tservice;varStarted:boolean);beginCoInitialize (Nil); TryCon1.  Open; exceptLogMessage ('Database Connection Error'); End; Started:=True;End;procedureTservice2.servicepause (Sender:tservice;varPaused:boolean);beginPaused:=True;End;End.

Reference: http://www.cnblogs.com/key-ok/p/3358916.html

Write a template for a service program (many can be found online)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.