Windows 服务在卸载时不会停止且不会被删除 (Wix)
我在 stackoverflow 上看到了一些与此相关的问题,但它们似乎都没有解决我所观察到的特定行为。
我在 Wix 3.0 .wxs 文件中定义了一个 Windows 服务,如下所示。
<Component Id='Service' Guid='3c658a54-b236-11e0-bbf6-039615e482ae' >
<File Id='ServiceEXE' Name='m_agent_service.exe'
Vital='yes' Source='..\m_agent_service.exe'
KeyPath='yes' />
<ServiceInstall Id='MerakiServiceInstall'
Vital='yes'
Name='MerakiPCCAgent' DisplayName='Meraki Client Insight Agent $(env.VERSION)' Description="Meraki Client Insight Monitoring and Management Service"
Type='ownProcess' Interactive='no' Start='auto' ErrorControl='normal'>
</ServiceInstall>
<ServiceControl Id='MerakiServiceControl'
Name='MerakiPCCAgent'
Start='install' Stop='both' Remove='uninstall'
Wait='yes' />
</Component>
当我安装 .MSI 时,该服务已安装并运行。伟大的。
然后当我卸载时(通过运行 msiexec /x 或使用控制面板中的添加/删除软件),服务将继续运行并且不会被删除。事实上,服务本身的日志告诉我没有调用任何服务关闭代码。 (例如,当我使用“sc stop”时,我确实看到服务关闭代码干净地运行。)
以下是 msiexec /x 卸载日志中的一些重要部分:
MSI (s) (14:04) [11:33:54:692]: 1 application(s) had been reported to have files
in use.
Info 1603. The file C:\Program Files\Meraki\PCC Agent 1.0.67\m_agent_service.exe
is being held in use by the following process: Name: m_agent_service, Id: 3120,
Window Title: '(not determined yet)'. Close that application and retry.
MSI (c) (40:78) [11:33:54:692]: File In Use: -m_agent_service- Window could not
be found. Process ID: 3120
MSI (c) (40:78) [11:33:54:692]: No window with title could be found for FilesInUse
[...]
Action start 11:33:57: UnpublishFeatures.
MSI (s) (14:04) [11:33:57:379]: Doing action: StopServices
MSI (s) (14:04) [11:33:57:379]: Note: 1: 2205 2: 3: ActionText
Action ended 11:33:57: UnpublishFeatures. Return value 1.
Action start 11:33:57: StopServices.
MSI (s) (14:04) [11:33:57:379]: Doing action: DeleteServices
MSI (s) (14:04) [11:33:57:379]: Note: 1: 2205 2: 3: ActionText
Action ended 11:33:57: StopServices. Return value 1.
Action start 11:33:57: DeleteServices.
MSI (s) (14:04) [11:33:57:379]: Doing action: RemoveFiles
[...]
MSI (s) (14:04) [11:33:57:645]: Product: Meraki Client Insight Agent -- Removal
completed successfully.
MSI (s) (14:04) [11:33:57:645]: Windows Installer removed the product. Product N
ame: Meraki Client Insight Agent. Product Version: 1.0.67. Product Language: 103
3. Removal success or error status: 0.
I've seen a few related questions on stackoverflow that relate to this one, but none of them seem to address the specific behavior I'm observing.
I have a Windows Service defined as follows in a Wix 3.0 .wxs file.
<Component Id='Service' Guid='3c658a54-b236-11e0-bbf6-039615e482ae' >
<File Id='ServiceEXE' Name='m_agent_service.exe'
Vital='yes' Source='..\m_agent_service.exe'
KeyPath='yes' />
<ServiceInstall Id='MerakiServiceInstall'
Vital='yes'
Name='MerakiPCCAgent' DisplayName='Meraki Client Insight Agent $(env.VERSION)' Description="Meraki Client Insight Monitoring and Management Service"
Type='ownProcess' Interactive='no' Start='auto' ErrorControl='normal'>
</ServiceInstall>
<ServiceControl Id='MerakiServiceControl'
Name='MerakiPCCAgent'
Start='install' Stop='both' Remove='uninstall'
Wait='yes' />
</Component>
When I install the .MSI, the service is installed and running. Great.
When I then uninstall (either by running msiexec /x or using the Add/Remove Software from the Control Panel), the service keeps on running and is not removed. In fact, the log of the service itself tells me that none of the service shutdown code has been invoked. (When I use "sc stop", for example, I do see service shutdown code running cleanly.)
Here are some salient parts from the msiexec /x uninstall log:
MSI (s) (14:04) [11:33:54:692]: 1 application(s) had been reported to have files
in use.
Info 1603. The file C:\Program Files\Meraki\PCC Agent 1.0.67\m_agent_service.exe
is being held in use by the following process: Name: m_agent_service, Id: 3120,
Window Title: '(not determined yet)'. Close that application and retry.
MSI (c) (40:78) [11:33:54:692]: File In Use: -m_agent_service- Window could not
be found. Process ID: 3120
MSI (c) (40:78) [11:33:54:692]: No window with title could be found for FilesInUse
[...]
Action start 11:33:57: UnpublishFeatures.
MSI (s) (14:04) [11:33:57:379]: Doing action: StopServices
MSI (s) (14:04) [11:33:57:379]: Note: 1: 2205 2: 3: ActionText
Action ended 11:33:57: UnpublishFeatures. Return value 1.
Action start 11:33:57: StopServices.
MSI (s) (14:04) [11:33:57:379]: Doing action: DeleteServices
MSI (s) (14:04) [11:33:57:379]: Note: 1: 2205 2: 3: ActionText
Action ended 11:33:57: StopServices. Return value 1.
Action start 11:33:57: DeleteServices.
MSI (s) (14:04) [11:33:57:379]: Doing action: RemoveFiles
[...]
MSI (s) (14:04) [11:33:57:645]: Product: Meraki Client Insight Agent -- Removal
completed successfully.
MSI (s) (14:04) [11:33:57:645]: Windows Installer removed the product. Product N
ame: Meraki Client Insight Agent. Product Version: 1.0.67. Product Language: 103
3. Removal success or error status: 0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
哦天哪,在上厕所的时候我突然灵机一动,我想我自己已经解决了这个问题——对这个帖子感到抱歉!我想我应该解释一下是什么解决了这个问题,以防万一其他与我一样阅读同一本书的初学者遇到同样的问题。
基本上,我更改了组件上的 Guid,重新安装,卸载,然后一切又恢复了。 (我认为更改指南可能不是最佳实践,但这对我有用。)
详细来说,我认为我的安装程序实际上根本没有问题 - 问题出在我用来测试安装的电脑上。我第一次尝试安装此 Windows 服务时没有使用 ServiceControl 元素,而只使用了 ServiceInstall 元素。然后我测试了安装,它起作用了,但显然该服务在卸载时没有自行删除。然后,我使用 Services.msc 从我的电脑手动停止并卸载了该服务。
然后我阅读了本书的下一部分,意识到我还需要一个 ServiceControl 元素,创建它并重新尝试安装程序 - 但我使用的是相同的 Guid。卸载仍然无法正常工作,我认为我在安装程序中做错了什么,因此上面的帖子。
我猜测发生的情况是,之前的安装使用相同的 Guid 但没有 ServiceControl 元素,导致我的电脑以某种方式损坏并阻止新的卸载程序正常完成。
让这成为我的一个教训——永远不要在你自己的电脑上测试你的安装程序!其中一条规则我完全理解并且很乐意忽略,直到它咬了我:)
Oh dear, whilst on the loo I had a brainwave and I think I have fixed it myself after all – sorry for the post! I think I shall explain what fixed it though in case any other beginners following the same Wix book as me run into the same issue.
Basically, I changed the Guid on my component, reinstalled, uninstalled and it all worked again. (I take on board that changing Guids may not be best practice, but this worked for me.)
To elaborate, I think there was actually no problem at all with my installer – the problem was on the PC I was using to test the installation. My first attempt at installing this windows service was done with no ServiceControl element, just the ServiceInstall element. I then tested the install, and it worked, but the service didn’t remove itself on uninstall, obviously. I then manually stopped and uninstalled the service from my PC using Services.msc.
I then read the next section of my book, realised I also needed a ServiceControl element, created it and re-tried the installer – but I was using the same Guid. The uninstall still didn’t work correctly and I assumed I’d done something wrong in my installer, hence the post above.
What I’m guessing had happened is that the previous install, using the same Guid but without the ServiceControl element, caused my PC to get corrupted somehow and prevented the new uninstaller from completing properly.
Let this be a lesson to me – never test your installer on your own PC! One of those rules I fully understand and happily ignore, till it bites me :)
检查详细日志文件并确保组件正在更改。该功能可能已关闭,或者某个组件/条件导致该组件被跳过。
Check the verbose log file and ensure the Component is being changed. It is possible the Feature is turned off or a Component/Condition is causing the Component to be skipped.