Skip to main content
 首页 » 编程设计

c#之检查是否成功卸载

2024年02月13日17wayfarer

我正在尝试自动化安装过程,在该过程中我卸载以前的版本并在顶部安装较新的版本。如果卸载成功,我应该如何测试(在我的 Bootstrap 中,用 C# 编码)?

这就是我目前启动卸载的方式。

Process p = Process.Start("msiexec", /*various switches*/); 
p.WaitForExit(); 

我目前也在纠结于动态多实例,这真的让我很费解,所以在 WiX 本身中处理这个问题即使不是不可能也是困难的。

请您参考如下方法:

您可以使用 Windows Installer API,而不是通过 msiexec 调用 Windows Installer。您可以通过 P/Invoke、激活 COM 接口(interface)或通过 WiX 的 DTF 包装器库来实现。用于删除产品的特定函数是 MsiConfigureProductEx .

使用 DTF,您可以这样做:

Installer.SetInternalUI(InstallUIOptions.Silent); 
Installer.SetExternalUI(UiHandler, InstallLogModes.Verbose); 
Installer.EnableLog(InstallLogModes.None, null); 
Installer.ConfigureProduct(productCode, 0, InstallState.Removed, ""); 
Console.WriteLine("RebootRequired: {0}   RebootInitiated: {1}", Installer.RebootRequired, Installer.RebootInitiated); 

UiHandler 委托(delegate)允许应用监控进度。如果有错误,DTF 会抛出异常。