卸载后取消注册com库

时间:2017-11-01 15:32:07

标签: c# com wix

我有一个库(Solidworks的插件),它实现了ComRegisterFunction,在RegisterFunction中添加了注册表的键。此外,我正在使用Wix工具集来创建安装程序。

当用户尝试卸载我的插件时,在卸载过程结束时有一个很小的时间间隔,当他按下取消时,所有文件都会恢复,但我的库将被取消注册。

作为解决方案,我尝试将库文件标记为“ Permanent ”并添加自定义操作以取消注册并在 InstallFinalize 之前将其删除。但它没有帮助。

我该如何处理这个问题?我的图书馆如何再次注册?

<InstallExecuteSequence>
  <Custom Action="setRegCommand" Before="comReg" />
  <Custom Action="setUnregCommand" Before="comUnreg" />
  <Custom Action="comReg" Before="InstallFinalize"> (NOT REMOVE) </Custom>
  <Custom Action="comUnreg" After="RemoveFiles"> REMOVE~="ALL" </Custom>
  <Custom Action="SetDeleteActionPropertyValues" Before="DeleteAction" />
  <Custom Action="DeleteAction" Before="InstallFinalize">REMOVE~="ALL"</Custom>
  <Custom Action="netWarning" Before="LaunchConditions">WIX_IS_NETFRAMEWORK_45_OR_LATER_INSTALLED = 0</Custom>
</InstallExecuteSequence>

<Fragment>
<CustomAction Id="SetDeleteActionPropertyValues" Property="DeleteAction" Value="INSTALLLOCATION=[INSTALLLOCATION];XXXINSTALLFOLDER=[XXXINSTALLFOLDER]" />
<CustomAction Id="DeleteAction" Return="check" Execute='commit' Impersonate='no' BinaryKey="CustomAction.CA.dll" DllEntry="DeleteFilesCA" />
<Binary Id='CustomAction.CA.dll' SourceFile='$(var.CustomAction.TargetDir)CustomAction.CA.dll'/>
</Fragment>

自定义操作

public static ActionResult DeleteFilesCA(Session session)
    {
        session.Log("Begin DeleteFilesCA");

        try
        {
            string installDir = session.CustomActionData["INSTALLLOCATION"];
            string xxxDir = session.CustomActionData["XXXINSTALLFOLDER"];
            if (Directory.Exists(installDir))
            {
                Directory.Delete(installDir, true);
                if(IsDirectoryEmpty(xxxDir))
                {
                    Directory.Delete(xxxDir);
                }
            }
        }
        catch (Exception e)
        {
            MessageBox.Show(e.Message);
        }

        return ActionResult.Success;
    }

    private static bool IsDirectoryEmpty(string path)
    {
        return !Directory.EnumerateFileSystemEntries(path).Any();
    }

com库的注册/注销

<Property Id ='comReg'/>
<CustomAction Id="setRegCommand" Property="comReg" Value='"[WindowsFolder]\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe" "[INSTALLLOCATION]\plugin.dll" /codebase' />
<CustomAction Id="comReg" BinaryKey="WixCA" DllEntry="WixQuietExec64"
            Execute="deferred" Return="check" Impersonate="no"/>

<Property Id='comUnreg'/>
<CustomAction Id="setUnregCommand" Property="comUnreg" Value='"[WindowsFolder]\Microsoft.NET\Framework64\v4.0.30319\RegAsm.exe" "[INSTALLLOCATION]\plugin.dll" /codebase /unregister' />
<CustomAction Id="comUnreg" BinaryKey="WixCA" DllEntry="WixQuietExec64"
            Execute="deferred" Return="ignore" Impersonate="no"/>

0 个答案:

没有答案