在使用wix卸载之前关闭systemtray应用程序

时间:2014-10-09 14:56:38

标签: wix windows-installer custom-action wix3.7

我知道过去曾问过类似的问题,但到目前为止我还没有找到解决问题的方法。

我有一个正在运行的系统托盘应用程序,我想在卸载开始之前将其关闭并显示“FileInUse”对话框,但无论我做什么似乎都不起作用。为了关闭我的系统托盘应用程序,我需要在安装它的文件夹中创建一个文件。该应用程序然后删除该文件并自行关闭。

根据我的尝试,我遇到了以下问题:

1)显示“FileInUse”对话框。没有好的

2)未能调用我的自定义操作,该操作会创建一个文件来通知我的系统托盘应用程序它应该关闭。

Error   1   ICE77: CloseAgentMonitor is a in-script custom action.  It must be 
sequenced in between the InstallInitialize action and the InstallFinalize action in 
the InstallExecuteSequence table

3)如果我将我的应用程序文件夹作为CustomData参数传递给CustomAction,如果我将其设置为Immediate而不是Immediate,但是如果我将其设置为Deferred },我得到了2)中提到的错误

4)我尝试过在RemoveFilesInstallValidateInstallFinalize之前调用自定义操作的不同方案。

由于我不确定什么是正确的序列,有人可以告诉我如何以及何时调用我的CustomAction以便触发“删除”按钮关闭或文件开始被删除之前。

我希望在卸载文件时以及显示FileInUse对话框之前执行此操作。

请注意,我可以在无声或可视卸载中处理此问题。

感谢。

更新

我可能应该发布我的wix代码:

<!-- Set variables required by the CloseAgentMonitor CustomAction -->
<CustomAction Id="CloseAgentMonitorSetProp"
      Return="check"
      Property="CloseAgentMonitor"
      Execute="immediate"
      Value="APPLICATIONFOLDER=[APPLICATIONFOLDER]" />

<!-- Define CustomAction to close the Agent on uninstall -->
<CustomAction Id="CloseAgentMonitor"
      Return="check"
      Execute="immediate"
      BinaryKey="CustomActions.CA"
      DllEntry="CloseAgentMonitor" />


<InstallExecuteSequence>
  <!- Make sure to set the props before the CloseAgentMonitor custom action -->
  <Custom Action="CloseAgentMonitorSetProp" Before="CloseAgentMonitor">
    <![CDATA[(Installed AND NOT UPGRADINGPRODUCTCODE)]]>
  </Custom>

  <Custom Action="CloseAgentMonitor" Before="InstallValidate">
    <![CDATA[(Installed AND NOT UPGRADINGPRODUCTCODE)]]>
  </Custom>
  ...

CustomAction更改为立即并将其设置为在InstallValidate之前调用,以解决2中提到的问题,但它会返回第3点中提到的错误,其中显示为{{1} 1}}没有被设置,甚至认为它应该是因为它在CustomActionData之前调用。

您可以从我的日志中清楚地看到它是:

CustomAction

但正如您可以看到我的MSI (s) (30:08) [16:22:47:148]: Doing action: CloseAgentMonitorSetProp MSI (s) (30:08) [16:22:47:148]: Note: 1: 2205 2: 3: ActionText Action 16:22:47: CloseAgentMonitorSetProp. Action start 16:22:47: CloseAgentMonitorSetProp. MSI (s) (30:08) [16:22:47:148]: PROPERTY CHANGE: Adding CloseAgentMonitor property. Its value is 'APPLICATIONFOLDER=C:\Program Files (x86)\Company\Client\'. Action ended 16:22:47: CloseAgentMonitorSetProp. Return value 1. 被调用时,它会在尝试访问CustomAction时触发错误。

APPLICATIONFOLDER

2 个答案:

答案 0 :(得分:2)

我想通了!!

我无法相信就是这么简单!我需要花费数小时查看它,将session.CustomActionData["APPLICATIONFOLDER"]更改为session["APPLICATIONFOLDER"]

我最初开始使用会话变量,但遇到了各种问题,所以我最终使用了CustomActionData,但我刚刚检查过,所有自定义操作都推迟到现在。

因此,如果我正确使用Wix,您应该在延迟CustomActionData中使用CustomAction,并且您应该立即使用会话的变量CustomAction

因此,自定义操作中的代码应为:

string applicationFolder = session["APPLICATIONFOLDER"];

而不是

string applicationFolder = session.CustomActionData["APPLICATIONFOLDER"];

希望这有助于其他人!

答案 1 :(得分:0)

正在使用的文件检测由InstallValidate操作执行,该操作在InstallInitialize之前。假设您的代码正常运行,请将其作为立即自定义操作运行,并且在InstallValidate之前应该没问题。

为什么需要在同一个文件夹中创建文件?它似乎与您的文件使用问题无关。关闭正在运行的应用程序的常用方法是向其发送关闭消息。 WiX有一个CloseApp自定义操作,可以做到这一点。

就是这个,它说了类似的事情:

WiX close application before uninstall - close open applications message