【发布时间】:2014-10-09 14:56:37
【问题描述】:
我知道过去有人问过类似的问题,但我至今仍未找到解决问题的方法。
我有一个正在运行的系统托盘应用程序,我想在卸载开始之前关闭它并显示“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) 如果我将应用程序文件夹设置为 Immediate 而不是 Immediate,则无法将我的应用程序文件夹作为 CustomData 参数传递给 CustomAction,但如果我将其设置为 Deferred,则会收到中提到的错误2)
4) 我尝试了在 RemoveFiles、InstallValidate、InstallFinalize 之前调用自定义操作的不同场景。
由于我不确定什么是正确的序列,有人可以告诉我如何以及何时调用我的 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 点中提到的错误,似乎我的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 时触发错误。
MSI (s) (30:08) [16:22:47:148]: Doing action: CloseAgentMonitor
MSI (s) (30:08) [16:22:47:148]: Note: 1: 2205 2: 3: ActionText
Action 16:22:47: CloseAgentMonitor.
Action start 16:22:47: CloseAgentMonitor.
MSI (s) (30:1C) [16:22:47:148]: Invoking remote custom action. DLL:
C:\Windows\Installer\MSI57B2.tmp, Entrypoint: CloseAgentMonitor
MSI (s) (30:C0) [16:22:47:148]: Generating random cookie.
MSI (s) (30:C0) [16:22:47:148]: Created Custom Action Server with PID 2528 (0x9E0).
MSI (s) (30:F4) [16:22:47:195]: Running as a service.
MSI (s) (30:F4) [16:22:47:195]: Hello, I'm your 32bit Impersonated custom action server.
SFXCA: Extracting custom action to temporary directory: C:\Windows\Installer\MSI57B2.tmp-\
SFXCA: Binding to CLR version v4.0.30319
Calling custom action CustomActions!CustomActions.CustomActions.CloseAgentMonitor
CloseAgentMonitor - Start
IsAgentMonitorRunning - Start
Checking if Agent Monitor is running.
Agent Monitor running: True
IsAgentMonitorRunning - End
Checking CustomActionData - Start
Checking CustomActionData - End
Exception thrown by custom action:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of
an invocation. ---> System.Collections.Generic.KeyNotFoundException: The given key was
not present in the dictionary. at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Microsoft.Deployment.WindowsInstaller.CustomActionData.get_Item(String key)
at CustomActions.CustomActions.CloseAgentMonitor(Session session)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object arguments, Signature sig,
Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object parameters,
Object arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder
binder, Object parameters, CultureInfo culture)
at Microsoft.Deployment.WindowsInstaller.CustomActionProxy.InvokeCustomAction(Int32
sessionHandle, String entryPoint, IntPtr remotingDelegatePtr)
CustomAction CloseAgentMonitor returned actual error code 1603 (note this may not be 100%
accurate if translation happened inside sandbox)
Action ended 16:22:47: CloseAgentMonitor. Return value 3.
Action ended 16:22:47: INSTALL. Return value 3.
【问题讨论】:
标签: wix windows-installer custom-action wix3.7