Self-starting configurable service | ||||||
Step 3. Self starting/self stopping | ||||||
Well, now the thing I promised in the forum - the self-starting service. The idea: let's check the command line and if the /start switch is there then simply execute a service starting code. In other case let's check it for the /stop switch. Of course if the /start or /stop switches are found then application should be stopped after execution of starting/stopping code. So the application code should be modified as shown below:
Note that the service name is not checked in this code. So our application can be used instead of "net start" command. To complete it the StartService and StopService methods should be implemented. These methods are standard and the similar code exists on many Delphi sites over the net. Well, the StartService looks like:
and the StopService method is almost the same:
Well, the second part of our example is finished and can be tested. Try to execute our example with the following switches in the command line: SvComEx22.exe /start:Ex22SvcA SvComEx22.exe /stop:Ex22SvcA You will see that service starts and stops as required. There is no need in external controller like net or svcomsc commands. Note that our example still require the SvComSvc.dll on Win9x/ME systems to be executed. If you are a register user you can simply attach the sources of this dll to our example and remove this last external dll. As a result you will have completely independent, self starting, configurable and multi-service application. On the next step we shall solve one more task: communication with service using Windows messages. The source code of this step is available here (zip, 3.1kb). |
||||||
<< | Index | Step 1 | Step 2 | Step 3 | Step 4 | Step 5 | >> | ||||||
Add your comment | Read comments |
© 1998-2001
Alexey Dynnikov |