开发者

Installer cannot start the service under User

开发者 https://www.devze.com 2023-03-20 11:45 出处:网络
Installer installs windows service. I provide form to user to select one of accounts to start the service:

Installer installs windows service. I provide form to user to select one of accounts to start the service:

  1. Local service
  2. Local System
  3. Network System
  4. User account

When I select User and enter Domain\Administrator account + pwd during the installation, service cannot be started.

When I select Local Service it started ok. After this I can change manually account 开发者_如何学编程to the same Domain\Administrator account and it started ok. Why such different behavior? How I can start service during the installation under any users' account?


Take a look at the Util Extensions User element. You can set the CreateUser attribute to no, the Name attribute to the [PROPERTY] that you are using in your UI for UserName Input and the LogonAsService attribute to yes. This will instruct WiX to grant your user the LogOnAsService right without having to write a custom action to call ntrights.exe.

Here's a sample as requested:

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
  <Product Id="*" Name="Setup" Language="1033" Version="1.0.0.0" Manufacturer="test" UpgradeCode="5c6b0f52-d024-4f1b-bfae-2dbb96b3ef15">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate EmbedCab="yes" />
    <UIRef Id="WixUI_Minimal" />
    <Feature Id="ProductFeature" Title="Setup" Level="1">
      <ComponentRef Id="serviceComponent" />
    </Feature>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="Setup">
          <Component Id="serviceComponent" Guid="380bbddd-daa7-0744-517b-37da768f5570">
            <File Id="serviceFile" Source="$(var.WindowsService.TargetPath)" KeyPath="yes" />
            <ServiceInstall Id="serviceInstall" Name="WindowsService" DisplayName="WindowsService" Start="auto" Type="ownProcess" ErrorControl="ignore" Account=".\serviceaccount" Password="p2Ekutrekac34ph2" />
            <ServiceControl Id="serviceControl" Name="WindowsService" Start="install" Stop="both" Remove="both" Wait="no" />
              <util:User Id="user" CreateUser ="yes" Name ="serviceaccount" Password="p2Ekutrekac34ph2" LogonAsService="yes" UpdateIfExists="yes" RemoveOnUninstall="yes" PasswordNeverExpires="yes" FailIfExists="no" Domain="[ComputerName]" CanNotChangePassword="yes" Disabled="no" PasswordExpired="no"/> 
          </Component>
        </Directory>
      </Directory>
    </Directory>
  </Product>
</Wix>


You need to make sure that the selected user account has the right to log on as a service. It doesn't matter if you are an Administrator, you cannot install services for an user without giving him the log on right.

If setting this policy works, you also need to do it dynamically during install. A solution is to use ntrights.exe as a custom action. This custom action can use your custom properties which contains the user account information.


In case anyone wonders why the code from @Christopher Painter his answer didn't work. I had similar code that didn't work with error 1923.

Error 1923. Service '' () could not be installed. Verify that you have sufficient privileges to install system services. MSI (s) (10:08) [15:55:00:161]: Product: '' (64 bit) -- Error 1923. Service '' () could not be installed. Verify that you have sufficient privileges to install system services.

Until I found that services.msc dialog needs to be closed during installation.

No idea why, but it works. During development services.msc was open all the time, so I never noticed.

0

精彩评论

暂无评论...
验证码 换一张
取 消