Windows services Can';t删除文件夹WIX安装程序

Windows services Can';t删除文件夹WIX安装程序,windows-services,windows-installer,wix3.6,Windows Services,Windows Installer,Wix3.6,我有一个由WIX安装程序安装的服务: <Component Id="cmp_myService" Guid="{5FC8815E-33T8-4C3D-9654-849EE4CB1E22}"> <File Id="f_myService" Name="MyService.exe" Source="$(var.SourcePath)MyService.exe" KeyPath

我有一个由WIX安装程序安装的服务:

<Component Id="cmp_myService" Guid="{5FC8815E-33T8-4C3D-9654-849EE4CB1E22}">
    <File Id="f_myService" Name="MyService.exe" Source="$(var.SourcePath)MyService.exe" KeyPath="yes" />
    <ServiceInstall Id="si_myServiceInstall" Name="My Service" DisplayName="It is my service" Type="ownProcess" Interactive="yes" Start="auto" ErrorControl="normal" Description="Here is some description" />
    <ServiceControl Id="sc_startStopMyService" Name="My Service" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
</Component>
我计划此自定义操作在执行序列中的
DeleteServices
操作之后立即运行。我假设此时应该停止并删除
MyService.exe
。但是我得到一个异常
对路径'MyService.exe'的访问被拒绝
,这意味着该服务尚未被删除。为什么会发生这种情况?我的自定义操作应该安排在哪里以确保服务已被删除

相关日志文件:

MSI (s) (64:3C) [08:42:32:597]: Doing action: StopServices
MSI (s) (64:3C) [08:42:32:597]: Note: 1: 2205 2:  3: ActionText 
Action ended 8:42:32: UnpublishFeatures. Return value 1.
Action start 8:42:32: StopServices.
MSI (s) (64:3C) [08:42:32:597]: Doing action: DeleteServices
MSI (s) (64:3C) [08:42:32:597]: Note: 1: 2205 2:  3: ActionText 
Action ended 8:42:32: StopServices. Return value 1.
Action start 8:42:32: DeleteServices.
MSI (s) (64:3C) [08:42:32:597]: Doing action: ca1_removeInstallDirOnUnsinstall
MSI (s) (64:3C) [08:42:32:597]: Note: 1: 2205 2:  3: ActionText 
Action ended 8:42:32: DeleteServices. Return value 1.
MSI (s) (64:80) [08:42:32:597]: Invoking remote custom action. DLL: C:\windows\Installer\MSIA125.tmp, Entrypoint: RemoveInstallDirRecursively
MSI (s) (64:B8) [08:42:32:597]: Generating random cookie.
MSI (s) (64:B8) [08:42:32:597]: Created Custom Action Server with PID 6176 (0x1820).
MSI (s) (64:98) [08:42:32:644]: Running as a service.
MSI (s) (64:B4) [08:42:32:644]: Hello, I'm your 32bit Impersonated custom action server.
Action start 8:42:32: ca1_removeInstallDirOnUnsinstall.
SFXCA: Extracting custom action to temporary directory: C:\windows\Installer\MSIA125.tmp-\
SFXCA: Binding to CLR version v4.0.30319
Calling custom action CustomAction!CustomAction.FilesAndFoldersCustomAction.RemoveInstallDirRecursively
Access to the path 'MyService.exe' is denied.
InstallFinalize
删除服务
发生在
安装文件
之前。我想
msiexec.exe
可能会锁定文件夹,以便作为主要升级的一部分重新安装,但我不确定(使用:,)查找锁定)。您可以将删除操作放在InstallFinalize之前(该操作将结束更改系统的提升操作)。这个位置应该可以工作,但不能保证。“核”整个文件夹不是一个好的做法

最佳实践:一般情况下,你不应该删除整个文件夹(这是相当危险的-搞乱一些东西,最终可能会删除一半的计算机。说真的。我见过这种情况发生。不是用MSI,而是用“cleanup EXE”)。我会将日志文件放在用户配置文件或
%ProgramFiles%
之外的其他位置。或者可以使用
事件日志
甚至使用数据库在线上传,以避免留下太多文件

仍然可以接受:我认为不应尝试自动卸载日志文件和其他用户数据。为什么?它们是用户数据——换句话说:它们属于用户。你不能简单地删除它们?如果他们想分析数据或重新安装应用程序,我会将数据保留在原位(后者对于许可证密钥特别重要-您是否将其保留?)

WiX:WiX有几个内置的结构来帮助删除文件和文件夹。有内置的MSI变体(,)可以通过通配符或名称删除文件。然后是所描述的。请阅读这篇博文。我相信它可以递归地完成这项工作(所有子文件夹)。正如您所了解的,我不太使用这些构造,因为我喜欢其他清理方法。坦率地说,我只是尝试在PDF或在线KDB文章中记录清理过程


链接:


删除整个文件夹很少是一件好事。如果文件夹为空,MSI将自行执行此操作。您正在删除什么类型的文件?日志文件?@SteinÅsmul是的,我正在删除卸载process后留下的日志文件。这是一个非常全面的答案。我同意不动我的日志文件。非常感谢。另外,我尝试在InstallFinalize之后安排一个操作,只是为了测试,它确实有效,所以尽管我还没有测试锁定场景,但我几乎可以肯定你就在这里。它在InstallFinalize之后似乎有效。在
InstallFinalize
之后,该操作将不会以提升方式运行,因此如果它尝试执行需要提升访问权限的操作,它将失败。当您以管理员身份启动整个安装程序时,它可能会工作。当您在正常用户帐户登录的情况下运行安装程序时,会显示故障(是的,这可以通过策略或分发系统实现)。在
InstallFinalize
之后,操作也会立即执行,这意味着它会在安装过程中直接运行,可能会运行两次(取决于一些技术细节)。
MSI (s) (64:3C) [08:42:32:597]: Doing action: StopServices
MSI (s) (64:3C) [08:42:32:597]: Note: 1: 2205 2:  3: ActionText 
Action ended 8:42:32: UnpublishFeatures. Return value 1.
Action start 8:42:32: StopServices.
MSI (s) (64:3C) [08:42:32:597]: Doing action: DeleteServices
MSI (s) (64:3C) [08:42:32:597]: Note: 1: 2205 2:  3: ActionText 
Action ended 8:42:32: StopServices. Return value 1.
Action start 8:42:32: DeleteServices.
MSI (s) (64:3C) [08:42:32:597]: Doing action: ca1_removeInstallDirOnUnsinstall
MSI (s) (64:3C) [08:42:32:597]: Note: 1: 2205 2:  3: ActionText 
Action ended 8:42:32: DeleteServices. Return value 1.
MSI (s) (64:80) [08:42:32:597]: Invoking remote custom action. DLL: C:\windows\Installer\MSIA125.tmp, Entrypoint: RemoveInstallDirRecursively
MSI (s) (64:B8) [08:42:32:597]: Generating random cookie.
MSI (s) (64:B8) [08:42:32:597]: Created Custom Action Server with PID 6176 (0x1820).
MSI (s) (64:98) [08:42:32:644]: Running as a service.
MSI (s) (64:B4) [08:42:32:644]: Hello, I'm your 32bit Impersonated custom action server.
Action start 8:42:32: ca1_removeInstallDirOnUnsinstall.
SFXCA: Extracting custom action to temporary directory: C:\windows\Installer\MSIA125.tmp-\
SFXCA: Binding to CLR version v4.0.30319
Calling custom action CustomAction!CustomAction.FilesAndFoldersCustomAction.RemoveInstallDirRecursively
Access to the path 'MyService.exe' is denied.