使用wix卸载之前,请关闭systemtray应用程序 [英] Close a systemtray app before uninstalling using wix
问题描述
我知道过去曾问过类似的问题,但到目前为止我仍然没有找到解决问题的方法。
I know similar questions have been asked in the past but I still haven't managed to find a solution to my problem as of yet.
我有一个正在运行的系统任务栏应用程序,我想在卸载开始之前将其关闭,并显示 FileInUse对话框,但我正在执行的操作似乎无效。为了关闭我的系统任务栏应用程序,我需要在安装文件的文件夹中创建一个文件。然后,应用程序将删除文件并自行关闭。
I've got a system tray app that's running and I want to close it before uninstall begins and displays the "FileInUse" dialog but whatever I'm doing doesn't appear to work. In order to close my system tray app, I need to create a file in the folder where it is installed. The app then deletes the file and closes itself.
根据我的尝试,我遇到以下问题:
I'm getting the following issues depending on what I've tried:
1)显示 FileInUse对话框。不好
1) The "FileInUse" dialog gets displayed. No good
2)无法调用我的自定义操作,该操作创建了一个文件来通知我的系统任务栏应用程序应关闭。
2) Failing to call my custom action which create a file to notify my system tray app that it should close.
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)如果将我的应用程序文件夹设置为立即
CustomAction >代替立即
,但是如果将其设置为 Deferred
,则会出现2)中提到的错误
3) Fails to pass my application folder as a CustomData parameter to the CustomAction
if I set it to Immediate
instead of Immediate
but if I set any it to Deferred
, I get the error mentioned in 2)
4)我尝试了不同的场景,不同于在 RemoveFiles
, InstallValidate
, InstallFinalize
。
4) I've tried different scenarios from calling the custom action before RemoveFiles
, InstallValidate
, InstallFinalize
.
由于我不确定正确的顺序是什么,有人可以告诉我如何以及何时调用我的CustomAction,以便触发它, Remove按钮已关闭,或者在文件开始被删除之前。
As I'm not sure what are the correct sequences, can someone tell me how and when to call my CustomAction so that it is triggered the "Remove" button is closed or before the files starts to get removed.
我想在卸载文件时并且在显示 FileInUse
对话框之前执行此操作。
I want to do this when uninstalling the files and before the FileInUse
dialog is displayed.
请注意,无论是静默卸载还是可视卸载,我都非常重要。
Note that it's really important that I can handle this in both silent or visual uninstall.
谢谢。
更新:
我可能应该发布我的wix代码:
I probably should have posted my wix code:
<!-- 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点中提到的错误,在那里我的<没有设置code> CustomActionData ,甚至认为应该这样,因为它是在 CustomAction
之前调用的。
Changing the CustomAction
to immediate and set it to be called before InstallValidate
sorts out the problem mentioned in 2, but it brings back the error mentioned in point 3, where it appears that my CustomActionData
is not being set, even thought it should be since it is called before the CustomAction
.
您可以从我的日志中清楚地看到它是:
You can clearly see from my logs that it is:
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
时会触发错误。
But as you can see when my CustomAction
is called, it triggers an error when trying to access the 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.
推荐答案
我知道了!
我简直不敢这么简单!我需要做的所有工作都花了几个小时,将 session.CustomActionData [ APPLICATIONFOLDER]
更改为 session [ APPLICATIONFOLDER]
。
I can't believe it was that simple! Spend hours looking into it when all I had to do, was change the session.CustomActionData["APPLICATIONFOLDER"]
to session["APPLICATIONFOLDER"]
.
我最初开始使用会话变量,但是遇到了各种问题,所以我最终使用了 CustomActionData
,但是我只是
I originally started using the session variables but hit various problems so I ended up using CustomActionData
but I've just checked and all my custom action were deferred up to now.
因此,如果我正确获取Wix,则应使用 CustomActionData
延后的 CustomAction
,则应在直接 CustomAction
中使用会话的变量。
So if I get Wix correctly, you should use CustomActionData
in deferred CustomAction
and you should use the session's variables in immediate CustomAction
.
因此您自定义操作中的代码应为:
So code in your custom action should be:
string applicationFolder = session["APPLICATIONFOLDER"];
而不是
string applicationFolder = session.CustomActionData["APPLICATIONFOLDER"];
希望这对其他人有帮助!
Hope this helps someone else!
这篇关于使用wix卸载之前,请关闭systemtray应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!