the service (just beeps the speaker every 5 secs) :<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes,SvcMgr, ExtCtrls ;<br><br>type<br> TService2 = class(TService)<br> Timer1: TTimer;<br> procedure Timer1Timer(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> function GetServiceController: TServiceController; override;<br> { Public declarations }<br> end;<br><br>var<br> Service2: TService2;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure ServiceController(CtrlCode: DWord); stdcall;<br>begin<br> Service2.Controller(CtrlCode);<br>end;<br><br>function TService2.GetServiceController: TServiceController;<br>begin<br> Result := ServiceController;<br>end;<br><br>procedure TService2.Timer1Timer(Sender: TObject);<br>begin<br>MessageBeep(1);<br>end;<br><br>end.<br><br><br><br>control app(not nessesary if you use control panel) :<br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls,WinSvc;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>function ServiceStart(sMachine, sService: String) : Boolean;<br>var<br> schm, schs: SC_Handle;<br> ss: TServiceStatus;<br> psTemp: PChar;<br> dwChkP: DWord;<br>begin<br> ss.dwCurrentState := 0;<br> schm := OpenSCManager(PChar(sMachine), nil, SC_MANAGER_CONNECT);<br> if (schm>0) then<br> begin<br> schs := OpenService(schm, PChar(sService), SERVICE_START or<br>SERVICE_QUERY_STATUS);<br> if (schs>0) then<br> begin<br> psTemp := nil;<br> if (StartService(schs, 0, psTemp)) then<br> if (QueryServiceStatus(schs, ss)) then<br> while (SERVICE_RUNNING<>ss.dwCurrentState) do<br> begin<br> dwChkP := ss.dwCheckPoint;<br> Sleep(ss.dwWaitHint);<br> if (not QueryServiceStatus(schs, ss)) then<br> Break;<br> if ss.dwCheckPoint <> 0 then<br> Break;<br> end;<br> CloseServiceHandle(schs);<br> end;<br> CloseServiceHandle(schm);<br> end;<br> Result := SERVICE_RUNNING=ss.dwCurrentState;<br>end;<br><br>function ServiceStop(sMachine, sService: String) : Boolean;<br>var schm, schs: SC_Handle;<br> ss: TServiceStatus;<br> dwChkP: DWord;<br>begin<br>schm := OpenSCManager(PChar(sMachine), nil, SC_MANAGER_CONNECT);<br> if (schm>0) then begin<br> schs := OpenService(schm, PChar(sService), SERVICE_STOP or<br>SERVICE_QUERY_STATUS);<br> if (schs>0) then<br> begin<br> if (ControlService(schs, SERVICE_CONTROL_STOP, ss)) then<br> if (QueryServiceStatus(schs, ss)) then<br> while (SERVICE_STOPPED<>ss.dwCurrentState) do<br> begin<br> dwChkP := ss.dwCheckPoint;<br> Sleep(ss.dwWaitHint);<br> if (not QueryServiceStatus(schs, ss)) then<br> Break;<br> if ss.dwCheckPoint <> 0 then<br> Break;<br> end;<br> CloseServiceHandle(schs);<br> end;<br> CloseServiceHandle(schm);<br> end;<br> Result := SERVICE_STOPPED=ss.dwCurrentState;<br>end;<br><br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>ServiceStart('','Service2');<br>file://ServiceStart('//computername','Alerter');<br>file://this would be for remote services<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>ServiceStop('','Service2');<br>end;<br><br>end.<br><br><br>you can also install it from code (still working on that part myself) using<br>CreateService etc..<br><br>theres very little docs on services so if anyone else has any feel free to<br>add here
<br>