【问题标题】:Execute uninstall with C#使用 C# 执行卸载
【发布时间】:2013-11-02 19:20:51
【问题描述】:

我一直在互联网上寻找这个,但我找不到它。

有没有办法通过 C# 触发卸载程序(从程序和功能屏幕)?还是出于安全目的而被 Windows 阻止?

【问题讨论】:

    标签: c# uninstallation


    【解决方案1】:

    您可以使用msiexec.exe。您可以使用product code 简单地卸载应用程序。使用命令可以设置卸载时显示 UI 还是静默卸载,

    string UninstallCommandString = "/x {0} /qn";

    • /qn:设置用户界面级别:无
    • /qb:设置用户界面级别:基本用户界面
    • /qr:设置用户界面级别:精简 UI
    • /qf:设置用户界面级别:Full UI(默认)

    C# code

    string UninstallCommandString = "/x {0} /qn";
    
    Process process = new Process();
    ProcessStartInfo startInfo = new ProcessStartInfo();
    process.StartInfo = startInfo;
    
    startInfo.UseShellExecute = false;
    startInfo.RedirectStandardError = true;
    
    startInfo.FileName = "msiexec.exe";
    startInfo.Arguments = string.Format(UninstallCommandString, "Product Code");
    
    process.Start();
    

    【讨论】:

    • @GuidoVisser 确保提供正确的安装产品代码。
    • 如何找到该程序的product code
    【解决方案2】:
    【解决方案3】:

    您可以使用 system.diagnostics 为卸载程序调用可执行文件。

    类似下面的东西应该可以解决问题:

    System.Diagnostics.Process.Start("/path/to/uninstall.exe", "arguments for uninstaller if needed, else don't bother with this arg");
    

    它又快又脏,/应该/工作。希望对您有所帮助。

    edit- 刚刚意识到您想从添加删除软件屏幕执行此操作。无论如何我都会把它留在这里,但我的错误。

    【讨论】:

      猜你喜欢
      • 2011-11-10
      • 2012-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多