使用 Microsoft.Deployment.WindowsInstaller.Installer.ConfigureProduct 静默卸载?
Using Microsoft.Deployment.WindowsInstaller.Installer.ConfigureProduct to uninstall silently?
我无法使用 ConfigureProduct 运行 安静地进行卸载。我有以下内容:
using Microsoft.Deployment.WindowsInstaller;
Installer.ConfigureProduct(productCode, 0, InstallState.Absent, "/q");
根据一些较早的 posts “/q” 应该可以工作,除了我每次 运行 代码时都会遇到以下异常。
"Invalid command line argument. Consult the Windows Installer SDK for detailed command line help."
请注意,“/q”在使用 msiexec.exe 时确实有效,但我想使用 Microsoft.Deployment.WindowsInstaller。
我还尝试使用以下方法将 UI 设置为静音:
Installer.SetInternalUI(InstallUIOptions.Silent);
Installer.ConfigureProduct(productCode, 0, InstallState.Absent, "");
但随后出现以下异常:
"Fatal error during installation."
从消息中我了解到 SetInternalUI 用于安装而不是卸载,但不确定。
我使用的是 WiX 3.9 R2 安装版本 2.0.50727 中的 DLL。
感谢任何帮助。谢谢!
编辑:我仔细查看了 "ConfigureProduct" 方法中 "commandLine" 参数的注释。
// commandLine:
// Specifies the command line property settings. This should be a list of the
// format Property=Setting Property=Setting.
所以基本上不行,你不能传递“/q”、“/l”或任何其他非 "Property=Setting" 形式的东西。答案中链接的参考 post 中的示例似乎是错误的。 (或者版本之间发生了一些变化,但我对此表示怀疑。)
尝试参考卸载 MSI 文件的不同方法(选项 6 描述了 DTF):
- Uninstalling an MSI file from the command line without using msiexec.
不幸的是,我目前没有 Visual Studio 可供测试 - 尽管我无法测试任何东西,但我仍然会试一试。不用说这让回答变得困难:
- 可能是您的静默卸载程序崩溃了,这就是它在静默模式下失败的原因。
- 通常这会涉及一个自定义操作,它可能没有被正确调节并且运行不当(或者根本没有,而 运行 在静默模式下)。
尝试在静默卸载期间启用日志记录,如此处所示(适当调整日志文件的路径)。特殊的 ! 标志将 刷新日志文件 - 这意味着它是连续写入而不是分批写入,因此不会因任何潜在的崩溃而丢失日志记录(这大大减慢了(卸载)安装过程:
using Microsoft.Deployment.WindowsInstaller;
public static void Uninstall( string productCode)
{
Installer.SetInternalUI(InstallUIOptions.Silent);
Installer.ConfigureProduct(productCode, 0, InstallState.Absent, "REBOOT=\"R\" /L*V! c:\uninstall.log");
}
要在日志文件中查找相关信息,请查看此 log file checking tip from Rob Mensching(Wix 的创建者)。
如果卸载正常且没有任何错误,那么最有可能的问题是卸载需要提升,而您的代码未 运行 提升,因此卸载失败。它不会在静默卸载期间要求用户提升!
SetInternalUI 适用于卸载。例如,以下 C++ 片段完全按照您的要求执行,使卸载完全无声:
INSTALLUILEVEL il = MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
UINT n = MsiConfigureProductEx(productid, INSTALLLEVEL_DEFAULT, INSTALLSTATE_ABSENT, L"REBOOT=R");
并且 ConfigureProduct 调用使用相同的 API。
Just to provide a better answer by linking to a new one:
Uninstalling program.
UAC 和 GUI:基本上您的静默卸载失败,因为它 运行s 没有提升。当 运行 交互时,您会收到 UAC 提示并可以提升权限 - 前提是您的帐户是管理员帐户并允许您这样做。当 运行 静默时,此提升不会发生并且卸载失败。解决方案是 运行 提升您的应用程序可执行文件。
异常处理:您可能还想使用适当的异常处理来确保因缺少提升而导致的错误消息报告给用户。有关示例,请参见上面 link 中的代码。这是一个快速内联部分:
try
{
Installer.SetInternalUI(InstallUIOptions.Silent); // Set MSI GUI level
Installer.ConfigureProduct(productcode, 0, InstallState.Absent, "REBOOT=\"ReallySuppress\"");
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.Message);
Console.ReadLine (); // Keep console window open
}
我无法使用 ConfigureProduct 运行 安静地进行卸载。我有以下内容:
using Microsoft.Deployment.WindowsInstaller;
Installer.ConfigureProduct(productCode, 0, InstallState.Absent, "/q");
根据一些较早的 posts “/q” 应该可以工作,除了我每次 运行 代码时都会遇到以下异常。
"Invalid command line argument. Consult the Windows Installer SDK for detailed command line help."
请注意,“/q”在使用 msiexec.exe 时确实有效,但我想使用 Microsoft.Deployment.WindowsInstaller。
我还尝试使用以下方法将 UI 设置为静音:
Installer.SetInternalUI(InstallUIOptions.Silent);
Installer.ConfigureProduct(productCode, 0, InstallState.Absent, "");
但随后出现以下异常:
"Fatal error during installation."
从消息中我了解到 SetInternalUI 用于安装而不是卸载,但不确定。
我使用的是 WiX 3.9 R2 安装版本 2.0.50727 中的 DLL。
感谢任何帮助。谢谢!
编辑:我仔细查看了 "ConfigureProduct" 方法中 "commandLine" 参数的注释。
// commandLine:
// Specifies the command line property settings. This should be a list of the
// format Property=Setting Property=Setting.
所以基本上不行,你不能传递“/q”、“/l”或任何其他非 "Property=Setting" 形式的东西。答案中链接的参考 post 中的示例似乎是错误的。 (或者版本之间发生了一些变化,但我对此表示怀疑。)
尝试参考卸载 MSI 文件的不同方法(选项 6 描述了 DTF):
- Uninstalling an MSI file from the command line without using msiexec.
不幸的是,我目前没有 Visual Studio 可供测试 - 尽管我无法测试任何东西,但我仍然会试一试。不用说这让回答变得困难:
- 可能是您的静默卸载程序崩溃了,这就是它在静默模式下失败的原因。
- 通常这会涉及一个自定义操作,它可能没有被正确调节并且运行不当(或者根本没有,而 运行 在静默模式下)。
尝试在静默卸载期间启用日志记录,如此处所示(适当调整日志文件的路径)。特殊的 ! 标志将 刷新日志文件 - 这意味着它是连续写入而不是分批写入,因此不会因任何潜在的崩溃而丢失日志记录(这大大减慢了(卸载)安装过程:
using Microsoft.Deployment.WindowsInstaller;
public static void Uninstall( string productCode)
{
Installer.SetInternalUI(InstallUIOptions.Silent);
Installer.ConfigureProduct(productCode, 0, InstallState.Absent, "REBOOT=\"R\" /L*V! c:\uninstall.log");
}
要在日志文件中查找相关信息,请查看此 log file checking tip from Rob Mensching(Wix 的创建者)。
如果卸载正常且没有任何错误,那么最有可能的问题是卸载需要提升,而您的代码未 运行 提升,因此卸载失败。它不会在静默卸载期间要求用户提升!
SetInternalUI 适用于卸载。例如,以下 C++ 片段完全按照您的要求执行,使卸载完全无声:
INSTALLUILEVEL il = MsiSetInternalUI(INSTALLUILEVEL_NONE, NULL);
UINT n = MsiConfigureProductEx(productid, INSTALLLEVEL_DEFAULT, INSTALLSTATE_ABSENT, L"REBOOT=R");
并且 ConfigureProduct 调用使用相同的 API。
Just to provide a better answer by linking to a new one: Uninstalling program.
UAC 和 GUI:基本上您的静默卸载失败,因为它 运行s 没有提升。当 运行 交互时,您会收到 UAC 提示并可以提升权限 - 前提是您的帐户是管理员帐户并允许您这样做。当 运行 静默时,此提升不会发生并且卸载失败。解决方案是 运行 提升您的应用程序可执行文件。
异常处理:您可能还想使用适当的异常处理来确保因缺少提升而导致的错误消息报告给用户。有关示例,请参见上面 link 中的代码。这是一个快速内联部分:
try
{
Installer.SetInternalUI(InstallUIOptions.Silent); // Set MSI GUI level
Installer.ConfigureProduct(productcode, 0, InstallState.Absent, "REBOOT=\"ReallySuppress\"");
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.Message);
Console.ReadLine (); // Keep console window open
}