Wix:卸载时停止Windows服务

evi*_*red 7 windows-services wix wix3

当我卸载我的服务时,我得到了错误,它说我必须在卸载之前停止这样的服务.这是不能令人满意的 - 卸载程序应该自动停止它.

我在几个月前发现了一个博客或新闻组的帖子,并让它正常工作,但现在它已停止为我工作.我没有链接到帖子......也许别人知道它在哪里?:)我想我改变了一些微妙的东西,它停止了工作.我发现Wix很难排除故障.

我正在使用以下include来从注册表中获取属性X_ WIN_ SERVICE_ NAME(抱歉,我不知道如何避免_转义在这里).它在安装时无关紧要,因为在那种情况下我使用输入文件显式设置它.这个包含在我的wxs文件中的任何组件之前使用.

<Include xmlns="http://schemas.microsoft.com/wix/2006/wi">

<?ifndef SetupXWinServiceRegistryProperties ?>
<?define SetupXWinServiceRegistryProperties ?>

<?define XWinServiceRegistryKey='Software\X\Y'?>

<Property Id="X_WIN_SERVICE_NAME">
  <RegistrySearch Id="XWinServiceNameSearch"
                    Root="HKLM"
                    Key="$(var.XWinServiceRegistryKey)"
                    Name="ServiceName"
                    Type="raw"/>
</Property>

<?endif?>
</Include>
Run Code Online (Sandbox Code Playgroud)

以下include组件用于在安装时保存注册表值:

<Include xmlns="http://schemas.microsoft.com/wix/2006/wi">

<?ifndef WriteXWinServiceRegistryProperties ?>
<?define WriteXWinServiceRegistryProperties ?>

<Component Id="CompWriteXWinServiceRegistryProps"
  Guid="some guid">

<!-- Write properties to the registry. Then they will be 
       accessable during uninstall. -->

<RegistryValue Root="HKLM"
   Key="$(var.XWinServiceRegistryKey)"
   Name="ServiceName"
   Type="string"
   Value="[X_WIN_SERVICE_NAME]"
   Action="write" />

</Component>

<?endif?>

</Include>
Run Code Online (Sandbox Code Playgroud)

我在安装后检查了我的系统,并在那里正确写入了注册表值.我的组件中设置服务的部分如下所示:

          <ServiceInstall Id="ServiceInstallXWinService"
                          Name="[X_WIN_SERVICE_NAME]"
                          Start="auto"
                          DisplayName="xxx"
                          Description="yyy"
                          Account="[X_WIN_SERVICE_USER]"
                          Password="[X_WIN_SERVICE_PASSWORD]"
                          Type="ownProcess"
                          ErrorControl="normal"
                          Vital="yes" />

          <ServiceControl Id="ServiceInstallXWinService" 
                          Name="[X_WIN_SERVICE_NAME]"
                          Stop="both"
                          Remove="uninstall"
                          Wait="yes" />
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Rob*_*ing 4

您确定卸载时 X_WIN_SERVICE_NAME 属性设置为正确的值吗?使用详细日志文件来确保搜索正确设置值。一切看起来都很好(虽然我不知道为什么你把所有东西都放在包含文件中而不是仅仅使用片段)。