i-net-software / SetupBuilder

Gradle plugin for building setups for different platforms.
Other
87 stars 21 forks source link

Question: how to run the Windows Service under a specific account #110

Closed MatthiasZerau closed 2 years ago

MatthiasZerau commented 2 years ago

I've successfully applied the plugin to built an MSI which runs a Java application as Windows Service. The Windows Service runs under the 'Local System' account.

How can this be changed to let the service run under a specific user account?

I can see that Apache Commons Daemon, which is used by this plugin, has command line parameters to specify such an service user, but it appears this plugin does not make use of those or expose it in any way.

Horcrux7 commented 2 years ago

The SetupBuilder plugin does not use the command line parameter from the Apache Commons Daemon. It use the MSI features (WIX toolset) that also an uninstall will work.

If you want specify a special account then you can set it for the ServiceInstall node in the wsx template. I think it can be Account and Password. https://wixtoolset.org/documentation/manual/v3/xsd/wix/serviceinstall.html

You can do this via wsx template https://github.com/i-net-software/SetupBuilder/wiki/Create-a-MSI-with-WSX-template

Or you patch the SetupBuilder (PR possible if working) in the file WxsFileBuilder.java in the lines 718 - 728.

MatthiasZerau commented 2 years ago

Hi @Horcrux7,

thanks for the prompt feedback. Your pointer to serviceinstall was the one I needed.

For reference, the following wsx template worked for me:

<?xml version="1.0" encoding="windows-1252"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
  <Product>
    <Property Id="ACCOUNT" Value="LocalSystem" Secure="yes"/>

    <DirectoryRef Id="INSTALLDIR">
      <Component Guid="3f61ac44-e384-3661-a996-f02747615b18" Id="xyz_service_service">
        <ServiceInstall Arguments=" &quot;//RS//xyz_service&quot;" Description="Xyz service doin xyz things" DisplayName="Xyz service" ErrorControl="normal" Id="xyz_service_service_install" Name="xyz_service" Start="auto" Type="ownProcess" Account="[ACCOUNT]" Password="[PASSWORD]"/>
      </Component>
    </DirectoryRef>
  </Product>
</Wix>