How to install a service for a custom user
The following article uses options that are available starting with the Enterprise edition and project type.
The Java Service Tutorial explains how to install a service under the LocalSystem account. However, if you want to install a service for a specific user, you need to make sure this user has enough privileges to install and start system services.
In order to be able to install system services, the user for which you install the service must be an Administrator. Also, this user must be able to log on as a service (this policy rule must be set for him).
I. Install a service for an existing user
You can configure a service installation for a custom user which is present on the target machine by following these steps:
- open the project file resulted after the Java Service Tutorial or a project which successfully installs a service
- go to the Properties Page page and create these properties: SERVICE_USER and SERVICE_PASSWORD
- set the values of these properties to the default username and password of the service (for example .\User and password); you can modify these properties throughout the installation (for example by using edit boxes on a custom dialog)
- go to the Services page and select your service
- in the Service Properties page set the "User Name" field to [SERVICE_USER] and the "Password" field to [SERVICE_PASSWORD]
- check Set "Log on as a service" policy for selected username option
You can verify if a user can log on as a service by using the "Local Security Policy" tool:
Control Panel -> Administrative Tools -> Local Security Policy\Local Policies\User Rights Assignment\Log on as a service
II. Install a service for a user created by your installation package
You can configure a service installation for a user which is created by the installation package by following these steps:
- go to Users and Groups page and create a new user named, for example, "User"
- in the "Password" field enter the desired password for this user account
- go to the Services page and select your service
- in the Properties page set the "User Name" field to .\User and the "Password" field to the password chosen at step 2
- check Set "Log on as a service" policy for selected username option
When using this approach, the prerequisite package will create your custom user. After its installation is finished, the main package will install the service for this custom user.