首页 > 解决方案 > WIX - 权限不足卸载服务

问题描述

我正在使用 WIX 安装程序为 Windows 服务构建安装包。我可以创建安装包,它会安装并启动有问题的服务,但我无法卸载该服务。卸载日志中的错误是:

MSI (s) (E4:E4) [11:51:15:117]: Error: 1060. Failed to change configuration of service Service Name because handle to the service could be obtained. Check if the service exists on the system.

其次是:

MSI (s) (E4:E4) [11:51:18:900]: Product: Service Name -- Error 1939. Service '' (Service Name) could not be configured.  This could be a problem with the package or your permissions. Verify that you have sufficient privileges to configure system services.

这是显示的错误。

在此处输入图像描述

这是我的 Product.wxs 中的组件配置。

<Component Id="$(var.TestImportService.TargetFileName)" Guid="7BCCB287-D4A5-42B9-B83B-E67E22D56D90">        
        <File Id="$(var.TestImportService.TargetFileName)" Name="$(var.TestImportService.TargetFileName)" Source="$(var.TestImportService.TargetPath)" KeyPath="yes" />
        <!-- Remove all files from the INSTALLFOLDER on uninstall -->
        <RemoveFile Id="ALLFILES" Name="*.*" On="uninstall" />
        <!-- Tell WiX to install the Service -->
        <ServiceInstall Id="ServiceInstaller"
                        Name="$(var.Name)"
                        Type="ownProcess"
                        DisplayName="$(var.Name)"
                        Description="The description."
                        Interactive="no"
                        Arguments="-start"
                        Vital="yes"
                        Start="auto"
                        ErrorControl="normal">
          <util:PermissionEx User="LocalSystem"
                             GenericAll="yes"
                             ServiceChangeConfig="yes"
                             ServiceEnumerateDependents="yes"
                             ChangePermission="yes"
                             ServiceInterrogate="yes"
                             ServicePauseContinue="yes"
                             ServiceQueryConfig="yes"
                             ServiceQueryStatus="yes"
                             ServiceStart="yes"
                             ServiceStop="yes" />
        </ServiceInstall>
        <!-- Tell WiX to start the Service -->
        <ServiceControl Id="ServiceInstaller" Name="$(var.Name)" Start="install" Stop="both" Remove="both" />
        <ServiceConfig ServiceName="$(var.Name)" DelayedAutoStart="1" PreShutdownDelay="5000" OnInstall="yes" OnReinstall="yes" OnUninstall="yes" />
      </Component>

我登录机器的帐户在机器的管理员组中。我没有正确设置什么来使卸载正常工作?

编辑:根据要求,我使用详细日志记录运行安装程序。这是我在日志中找到的命令行。

From Install Log
MSI (c) (48:44) [13:44:13:945]: Command Line: CURRENTDIRECTORY=C:\Users\user.name\Documents\Visual Studio Projects\TestService\TestServiceSetup\bin\Debug CLIENTUILEVEL=0 CLIENTPROCESSID=14664 

...

MSI (s) (DC:4C) [13:44:45:191]: Command Line: INSTALLFOLDER=C:\Program Files (x86)\Company Name\Test Service\ ROOTDIRECTORY=C:\Program Files (x86)\Company Name\ TARGETDIR=C:\ CURRENTDIRECTORY=C:\Users\user.name\Documents\Visual Studio Projects\TestService\TestServiceSetup\bin\Debug CLIENTUILEVEL=0 CLIENTPROCESSID=14664 USERNAME=Information Technology COMPANYNAME=Company Name SOURCEDIR=C:\Users\user.name\Documents\Visual Studio Projects\TestService\TestServiceSetup\bin\Debug\ ACTION=INSTALL EXECUTEACTION=INSTALL ROOTDRIVE=C:\ INSTALLLEVEL=1 SECONDSEQUENCE=1 ADDLOCAL=MainApplication ACTION=INSTALL 


From Uninstall Log
MSI (s) (9C:F4) [13:55:40:179]: Command Line: REMOVE=ALL CURRENTDIRECTORY=C:\Users\user.name\Documents\Visual Studio Projects\TestService\TestServiceSetup\bin\Debug CLIENTUILEVEL=2 CLIENTPROCESSID=5000 

标签: c#servicewixwix3

解决方案


看起来它在卸载和查看您的 WXS 期间无法找到该服务:

<ServiceControl Id="ServiceInstaller" Name="$(var.Name)" Start="install" Stop="both" Remove="both" />

您要求安装程序在安装和卸载时删除该服务。因此安装程序找不到要删除的服务,您能否将其更改为并重试:

<ServiceControl Id="ServiceInstaller" Name="$(var.Name)" Start="install" Stop="both" Remove="uninstall" />

删除 - 指定是否应在安装、卸载或同时通过 DeleteServices 操作删除服务。对于“安装”,只有在安装父组件时才会删除该服务(msiInstallStateLocal 或 msiInstallStateSource);对于“卸载”,只有在删除父组件时才会删除服务(msiInstallStateAbsent);对于“两者”,在这两种情况下都将删除该服务。

服务控制


推荐阅读