Home arrow Delphi-Kylix arrow Page 2 - Internet Access: Client Service
DELPHI-KYLIX

Internet Access: Client Service


When a workstation is switched on in our Internet cafe we need to have a way of ensuring that the client application, which communicates with the server, is also started. There are two ways of doing this: manually and automatically. You will probably want the application to load automatically. Windows services will let us accomplish this task. Keep reading to find out what they are and how to use them.

Author Info:
By: David Web
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
October 13, 2008
TABLE OF CONTENTS:
  1. · Internet Access: Client Service
  2. · The service application code
  3. · Code Explained
  4. · To Install/Uninstall the service

print this article
SEARCH DEVARTICLES

Internet Access: Client Service - The service application code
(Page 2 of 4 )

So far we have looked at what a service is and how it works. Now we will write the code to make our service active. Before we write the code, let's look at what we want our service to do.

Basically we want it to see if the client application is running. If it is not, then we want it to start the application, otherwise we want it to do nothing. The service must check every couple of seconds or minutes (depending on your choice) to see if the client application is active.

Below is the entire service application code. Note that I’ve now saved the unit as “icstarter.” I’ve also added a timer component. The following properties are set:


Displayname: iCafeService

Servicetype: stWin32

Starttype: stAuto

Interactive: True (for debugging purposes)


unit icstarter;


interface


uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,

ExtCtrls,shellapi;


type

TService1 = class(TService)

Timer1: TTimer;

procedure Timer1Timer(Sender: TObject);

procedure ServiceExecute(Sender: TService);

private

{ Private declarations }

public

function GetServiceController: TServiceController; override;

{ Public declarations }

end;


var

Service1: TService1;


implementation


{$R *.DFM}


procedure ServiceController(CtrlCode: DWord); stdcall;

begin

Service1.Controller(CtrlCode);

end;


function TService1.GetServiceController: TServiceController;

begin

Result := ServiceController;

end;


procedure TService1.ServiceExecute(Sender: TService);

begin

//activate the client application here

timer1.Enabled:=true;

while not terminated do

servicethread.ProcessRequests(true);

timer1.Enabled:=false;

end;


procedure TService1.Timer1Timer(Sender: TObject);

var

handle,h: HWND;

begin

handle:= FindWindow('TForm1', 'iClient');

if handle > 0 then

begin

showmessage('found it!');

end

else

begin

//startup the app here. Shellexec

shellexecute(h,'open','c:\intertimer\client\iclient.exe',nil,nil,0);

end;


end;


end.



blog comments powered by Disqus
DELPHI-KYLIX ARTICLES

- Loading an XML Document into the DOM
- Delphi Wrapper Classes and XML
- Delphi and the DOM
- Delphi and XML
- Internet Access: Client Service
- Finishing the Client for an Internet Access ...
- The Client for an Internet Access Control Ap...
- User Management for an Internet Access Contr...
- Important Procedures for an Internet Access ...
- Server Code for an Internet Access Control A...
- Constructing the Interface for an Internet A...
- Building a Server Application for an Interne...
- Building an Internet Access Control Applicat...
- Client Dataset: Working with Data Packets an...
- Using the Client Dataset in an N-Tiered Appl...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials