gpt4 book ai didi

windows-services - 使用WiX(2.0)安装多文件NT服务

转载 作者:行者123 更新时间:2023-12-04 18:17:13 24 4
gpt4 key购买 nike

如何在WiX中安装带有其他文件的服务,并定义实际的服务EXE文件是什么文件?

方案:我有一个仅是单个EXE文件的服务,并使用以下代码将其安装为WiX中的Windows NT服务:

<Component Id='InstallMyServiceComponent' Guid='{....}' DiskId='1'>
<File Id='InstallMyServiceEXEFile' LongName='MyService.exe'
Name='MyServ.exe' src='MyService/bin/release/MyService.exe' KeyPath='yes'/>
<ServiceInstall Id='InstallMyService' Name='MyService' Description='My Service'
ErrorControl='normal' Start='auto' Type='ownProcess' Vital='yes' />
<ServiceControl Id='UninstallMyService' Name='MyService' Remove='uninstall'
Wait='yes' />
</Component>
<Component Id='RunMyServiceComponent' Guid='.......'>
<ServiceControl Id='RunMyService' Name='MyService' Start='install'
Stop='uninstall' Wait='no' />
</Component>

并且我有一个功能,该功能随后可以安装并有选择地启动此服务。

现在,我的问题是-现在我的服务已经增长,并且单个EXE不再是单个EXE-它是多个文件,EXE,DLL和一些支持文件。

但是,我现在该如何安装呢?

我尝试将所有文​​件都包含在组件中
<Component Id="MyService" Guid="......" DiskId="1">
<File Id="fileMyService_framework_dll" LongName="Framework.dll"
Name="Framewrk.DLL" src="MyService\Framework.dll" />
<File Id="fileMyService_dal_dll" LongName="MyServiceDAL.dll"
Name="SrvcDAL.DLL" src="MyService\ServiceDAL.dll" />
<File Id="fileMyService_helpers_dll" LongName="Helpers.dll"
Name="Helpers.DLL" src="MyService\Helpers.dll" />
<File Id="fileMyService_exe" LongName="MyService.exe"
Name="MySrv.EXE" src="MyService\MyService.exe" />
</Component>

首先,我尝试仅将ServiceInstall和ServiceControl标记添加到此组件:
<Component Id="MyService" Guid="......" DiskId="1">
<File Id="fileMyService_framework_dll" LongName="Framework.dll"
Name="Framewrk.DLL" src="MyService\Framework.dll" />
<File Id="fileMyService_dal_dll" LongName="MyServiceDAL.dll"
Name="SrvcDAL.DLL" src="MyService\ServiceDAL.dll" />
<File Id="fileMyService_helpers_dll" LongName="Helpers.dll"
Name="Helpers.DLL" src="MyService\Helpers.dll" />
<File Id="fileMyService_exe" LongName="MyService.exe"
Name="MySrv.EXE" src="MyService\MyService.exe" />
<ServiceInstall Id='InstallMyService' Name='MyService'
Description='My Service' ErrorControl='normal' Start='auto'
Type='ownProcess' Vital='yes' />
<ServiceControl Id='UninstallMyService' Name='MyService'
Remove='uninstall' Wait='yes' />
</Component>

但是然后我的“Framework.dll”被设置为正在创建的服务的源路径.....

因此,我想我将使用ServiceInstall创建第二个组件来实际安装该服务,而我只是使用FileRef引用该服务EXE文件-但这似乎并不存在(至少在Wix2中如此)。
<Component Id='InstallMyServiceComponent' Guid='{....}' DiskId='1'>
<FileRef Id='fileMyService_exe' KeyPath='yes'/>
<ServiceInstall Id='InstallMyService' Name='MyService'
Description='My Service' ErrorControl='normal' Start='auto'
Type='ownProcess' Vital='yes' />
<ServiceControl Id='UninstallMyService' Name='MyService'
Remove='uninstall' Wait='yes' />
</Component>

因此,可怜的WiX作者必须做什么才能安装所有必需的文件,而仍然获得NT Service安装来选择正确的EXE文件(而不仅仅是组件文件列表中的任意文件)?

马克

最佳答案

ServiceInstall元素最终将指向ServiceInstall所在组件的“KeyPath”。默认情况下,WiX工具集选择组件中第一个File或RegistryKey元素作为KeyPath。当您将文件添加到组件时,列表顶部的.dll成为KeyPath。

通常,较小的组件优于较大的组件。因此,更好的解决方案是将DLL放在单独的组件中。然后,您可以将.exe File元素和ServiceInstall元素保留在同一组件中。这样就很干净了。

如果然后要将“服务”分组在一起,则可以创建ComponentGroup元素,并将ComponentRefs放入.exe和.dll组件中。现在,您可以从Feature/ComponentGroupRef中进行引用。

关于windows-services - 使用WiX(2.0)安装多文件NT服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1266313/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com