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.
The procedure first checks to see if a window with the caption "iClient" is active. This is done using the findwindow() function of the Windows API:
handle:= FindWindow('TForm1', 'iClient');
The result of the search is then stored in the "handle" variable. The next thing that we do is check to see if the handle contains any value:
if handle > 0 then
If the handle contains a value, then the client application is actually running, in which case we do nothing:
begin
//remove the showmessage function, its there for debugging purposes
showmessage('found it!');
end
If the handle does not contain any value, the client application is not running, so we start it up by using the shell API function called shellexecute():
There might be a small issue with the shellexec function because it is not portable, so make sure that all the workstations use the Windows operating system.
The service execute function is responsible for activating the timer component. Without this procedure the timer, which is deactivated, will stay deactivated and will not check to see if the client application is running: