You will see a confirmation dialog when the service has been successfully installed or an error message if it failed.
To install the service application you open a command prompt and type: Note that you need administrator rights to install and uninstall service applications, because it is necessary to write or delete registry entries in HKEY_LOCAL_MACHINE, and that requires permissions that normal or restricted users do not have. Windows won't run a service application if it's located on a network drive.įor this tutorial save the unit as MyServiceUnit.pas and the project as MyService.dpr. Let's first install the service and see if it can run.įirst save the project (File, Save All) in a folder on your local harddrive.
We haven't written a single line of code ourself yet, that will come shortly. I'll assume that you have created the service framework as shown above. For many things "Local System" is sufficient, however if the service needs to have access to things such as a folder on a network drive/share (which are normally user/password protected) you may need to specify an account which has been granted access to the network share. Many services runs as "Local System" unless you specify a specific username when installing the service.
You can always enter an account name and password in the service properties after the service has been installed.Ī service runs as a specific user and that means that a service has the same access permissions to different things such as folders as the account under which the service runs. Just leave ServiceStartName and Password empty. That requires that you know at design time the account name and password, and who knows that? You can specify an account name in this property and password in the Password property to specify which account the service should log on as. The DisplayName is used for displaying when you use the Control Panel, Administration, Services applet. HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application.Įnter a user friendly and descriptive name such as "Companyname SQL Database Special Something" (feel free to use spaces in the name). So be sure to use a name which will not be used by other services, otherwise you might end up with a nasty registry key name conflict with other services.Īlso we will later use the Name property ourself to create a key in the registry under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services. It's important to choose a good name, because when installing the service this name is automatically used to create a key in the registry under The TService class is where we do our stuff and it has a number of properties which you can see in the Object Inspector.Īmong the properties you will see a Name, DisplayName, ServiceStartName and Password property.Įnter a good descriptive name for your service in the Name property.ĭo not just leave the name as Service1, but choose a more descriptive name such as "CompanynameSqlDatabaseSpecialSomething" (no blanks in the name). You now have the framework for a service application which includes a TService class.
You need at least the Professional edition. Note that if you have the Standard edition of Delphi "Service Application" may not be available. Select the menu items File, New, Other and select "Service Application" and click OK.
Well, that's actually easy to do in Delphi. How do we create Windows Services in Delphi? The Tutorial assumes you have Delphi 7, but it should work the same in other Delphi versions. Install and Uninstall the service application
In this tutorial the following topics will be covered: Warning: Use of any files and information from this tutorial is at your own risk. This tutorial is not finished, it is a work in progress. Service Application Tutorial in Delphi Tutorial for making a Service Application using Delphi