wix - Wix 安装程序:安装的服务无法在启动时读取 HKLM 注册表项
问题描述
我正在使用 wix 工具 3.11 创建一个安装服务的 msi。安装程序运行自定义操作并将 vars 返回到 wix 以写入注册表 (HKLM)。服务启动并尝试读取注册表,但无法完成并且失败。如果我手动编写注册表,安装程序可以完美运行。
来自 msi 日志的错误消息:
Product: Installer-- Error 1920. Service 'XPTO Server' (xpto_server) failed to start. Verify that you have sufficient privileges to start system services.
我的维克斯 XML:
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" InstallPrivileges="elevated" />
...
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="CMP_RegistryEntries" Guid="xxxxxxxxx" >
<RegistryKey Root="HKLM" Key="SOFTWARE\XPTOInc\XPTO\XPTOServer\BetaVersion">
<RegistryValue Name="token" Action="write" Value="[TOKEN]" Type="string" KeyPath="yes" />
<RegistryValue Name="[IDENTIFIER_TYPE]" Action="write" Value="[INSTALLEDID]" Type="string" />
<RegistryValue Name="installDir" Action="write" Value="[INSTALLFOLDER]" Type="string" />
</RegistryKey>
</Component>
<Component Id="CMP_XPTOServerEXE" Guid="xxxxxx">
<File Id="FILE_XPTOServerEXE" Name="xpto-server.exe" Source="Work\xpto-server.exe" KeyPath="yes" />
<ServiceInstall Id="InstallExporterService" Name="xpto_server" DisplayName="XPTO Server" Description="Read data from Registry and do simple stuff" ErrorControl="normal" Start="auto" Type="ownProcess" />
<ServiceControl Id="ServiceStateControl" Name="xpto_server" Remove="uninstall" Start="install" Stop="both" />
</Component>
</ComponentGroup>
编辑:当我手动将变量写入注册表时,该服务使用 msi pkg 安装或使用 sc.exe 运行
编辑2:这里遵循设置注册表然后星服务的日志
MSI (s) (70:74) [15:40:37:560]: Created Custom Action Server with PID 16808 (0x41A8).
MSI (s) (70:E4) [15:40:37:613]: Running as a service.
MSI (s) (70:E4) [15:40:37:615]: Hello, I'm your 32bit Elevated Non-remapped custom action server.
MSI (s) (70:38) [15:40:37:973]: Executing op: ActionStart(Name=WriteRegistryValues,Description=Writing system registry values,Template=Key: [1], Name: [2], Value: [3])
Action 15:40:37: WriteRegistryValues. Writing system registry values
MSI (s) (70:38) [15:40:37:974]: Executing op: ProgressTotal(Total=3,Type=1,ByteEquivalent=13200)
MSI (s) (70:38) [15:40:37:975]: Executing op: RegOpenKey(Root=-2147483646,Key=SOFTWARE\XPTOInc\XPTO\XPTOServer\BetaVersion,,BinaryType=0,,)
MSI (s) (70:38) [15:40:37:975]: Executing op: RegAddValue(Name=token,Value=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,)
WriteRegistryValues: Key: \SOFTWARE\XPTOInc\XPTO\XPTOServer\BetaVersion, Name: token, Value: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
MSI (s) (70:38) [15:40:37:976]: Executing op: RegAddValue(Name=envId,Value=xxxxxxxxxxxxxxxxxxxxxxxx,)
WriteRegistryValues: Key: \SOFTWARE\XPTOInc\XPTO\XPTOServer\BetaVersion, Name: envId, Value: xxxxxxxxxxxxxxxxxxxxxxxxx
MSI (s) (70:38) [15:40:37:976]: Executing op: RegAddValue(Name=installDir,Value=C:\Program Files (x86)\XPTOInc\XPTO\XPTO Server Beta\,)
WriteRegistryValues: Key: \SOFTWARE\XPTOInc\XPTO\XPTOServer\BetaVersion, Name: installDir, Value: C:\Program Files (x86)\XPTOInc\XPTO\XPTO Server Beta\
MSI (s) (70:38) [15:40:37:977]: Executing op: ActionStart(Name=InstallServices,Description=Installing new services,Template=Service: [2])
Action 15:40:37: InstallServices. Installing new services
MSI (s) (70:38) [15:40:37:977]: Executing op: ProgressTotal(Total=1,Type=1,ByteEquivalent=1300000)
MSI (s) (70:38) [15:40:37:978]: Executing op: ServiceInstall(Name=xpto_server,DisplayName=XPTOServer,ImagePath="C:\Program Files (x86)\XPTOInc\XPTO\XPTO Server Beta\xpto-server.exe",ServiceType=16,StartType=2,ErrorControl=1,,Dependencies=[~],,,Password=**********,Description=Read data from Registry and do simple stuff,,)
InstallServices: Service:
MSI (s) (70:38) [15:40:37:980]: Executing op: ActionStart(Name=StartServices,Description=Starting services,Template=Service: [1])
Action 15:40:37: StartServices. Starting services
MSI (s) (70:38) [15:40:37:981]: Executing op: ProgressTotal(Total=1,Type=1,ByteEquivalent=1300000)
MSI (s) (70:38) [15:40:37:981]: Executing op: ServiceControl(,Name=xpto_server,Action=1,,)
StartServices: Service: XPTO Server
Error 1920. Service 'XPTO Server' (xpto_server) failed to start. Verify that you have sufficient privileges to start system services.
解决方案
解决方案:本例中的问题是由于 32 位 / 64 位问题,在注册表中的预期位置找不到注册表项。
- 64 位部分:
HKEY_LOCAL_MACHINE\SOFTWARE\Company\App
-MyValue
- 32位部分:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Company\App
-MyValue
回答结束。但是,将调试工作留在下面:
第一轮:
也许尝试阅读这两个最近的答案并检查是否有任何铃声:
它在事件查看器中说什么?( Windows+R eventvwr
和OK
)
第二轮:
- Bitness:你确定你是从注册表中的正确位置读取的吗?您安装的是 32 位 MSI 还是 64 位 MSI?(看起来像 32 位)
- 64位部分:
HKEY_LOCAL_MACHINE\SOFTWARE\Company\App
- 32位部分:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Company\App
- 64位部分:
- 权限:您是否检查了您的设置写入用于检查的注册表项和值的权限
regedit.exe
?Right click => Permissions
(不得不问)。 - 特权:您使用什么帐户来运行该服务?它有点像标准的LocalSystem?该帐户需要SeServiceLogonRight权限。有关详细信息,请参阅上面部分的第二行。
- 日志记录:您是否在服务中使用log4net或其他一些日志记录功能?您是否尝试过顶部第一个链接中的详细调试 MSI 日志记录?
推荐阅读
- c# - ASP.NET MVC 注销和返回按钮
- python - Bluetoothctl:在 Windows 机器上运行 rfkill
- javascript - 作为函数的道具是否属于 useEffect 依赖数组?
- php - PHP /比较两个包含条件的语句以获取它是真还是假
- python - Python时间和大小批处理器
- python - 关于 predict_prob() 函数的理论问题 - 概率的显示顺序
- terraform - Terraform HCL - 将列表转换为对象地图?
- r - 我可以将observeEvent() 与bsplus::bs_accordion 一起使用吗
- bash - 使用“nohup”时,打印功能在整个程序完成之前不会打印
- neo4j - 如何使用 ORDER BY 的查询参数?