How to install a service for a custom user

ImportantThe 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:

  1. open the project file resulted after the Java Service Tutorial or a project which successfully installs a service
  2. go to the Install Parameters page and create these properties: SERVICE_USER and SERVICE_PASSWORD
  3. 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)
  4. go to the Services page and select your service
  5. in the Service Properties page set the "User Name" field to [SERVICE_USER] and the "Password" field to [SERVICE_PASSWORD]
  6. 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

Windows Installer cannot install a service for a user which is created by the same package which installs the service. Therefore, if you want to install a service for a user you create, you can follow these steps:

  1. after you configured the project which installs the service for your custom user, create a new Advanced Installer Enterprise project
  2. in this new project use the Users and Groups page to configure your custom user
  3. in the Registry page create a registry value which contains the name of your user (this registry entry will be used to determine if the package which creates the user was installed)
  4. save and build this project
  5. add the resulted MSI package as a prerequisite for the package which installs the service
  6. use the registry value in the package which creates the user as the install condition of the prerequisite

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.