简体   繁体   English

尝试卸载应用程序但出现错误

[英]Trying to uninstall an application but getting an error

At work I have to uninstall the same application several times per day (and reinstall new versions). 在工作中,我每天必须多次卸载同一应用程序(并重新安装新版本)。 I'm trying to make a C# program that I can run that will do this all for me. 我正在尝试制作一个可以运行的C#程序,为我完成所有这些工作。 Right now, I'm stuck on the uninstall process. 现在,我在卸载过程中陷入困境。

The code I have runs and attempts to uninstall the application, but Windows gives me an error during this. 我运行的代码尝试卸载该应用程序,但是Windows在此期间给我一个错误。

Here's what I have right now: 这是我现在所拥有的:

static void Main(string[] args)
    {
      ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Product");
      const string prodName = "myApp";
      Console.WriteLine("searching...");
      foreach (ManagementObject wmi in searcher.Get())
      {
        if (wmi["Name"].ToString() == prodName)
        {
          Console.WriteLine("found");
          string productCode = "/x {" + wmi.Properties["IdentifyingNumber"].Value.ToString() + "}";
          Process p = new Process();
          p.StartInfo.FileName = "msiexec.exe";
          p.StartInfo.Arguments = productCode;
          p.Start();
          Console.WriteLine("Uninstalled");
          break;
        }
      }
      Console.ReadLine();
    }

This is the error I get when it tries to do the uninstall: 这是我尝试执行卸载时遇到的错误:

"This installation package could not be opened. Verify that the package exists and that you can access it, or contact the application vendor to verify that this is a valid Windows Installer package" “无法打开此安装程序包。请验证该程序包存在并且可以访问它,或者与应用程序供应商联系以确认这是有效的Windows Installer程序包”

Uninstall Reference : This old answer might have what you need: Uninstalling an MSI file from the command line without using msiexec . 卸载参考 :这个旧答案可能满足您的需要: 从命令行卸载MSI文件而不使用msiexec It shows various ways to uninstall an MSI. 它显示了多种卸载MSI的方法。

DTF : The DTF (Desktop Tools Foundation) included with the WiX toolset can be used to uninstall. DTFWiX工具集随附的DTF(桌面工具基金会)可用于卸载。 Here is some sample C# code: Uninstalling program - run elevated, quick link to sample . 以下是一些示例C#代码: 卸载程序 - 运行高级,快速链接至sample的程序

VBScript / COM : Here are some links to VBScript samples and various ways to uninstall ( uninstall by product name , uninstall by upgrade code , etc... ): WIX (remove all previous versions) - the uninstall by upgrade code (sample code towards bottom) is interesting because it generally works for all versions and incarnations of your installer (upgrade code tends to remain stable across releases). VBScript / COM :这是一些指向VBScript示例的链接,以及各种卸载方法( uninstall by product name uninstall by upgrade code etc... ): WIX(删除所有以前的版本) - 按升级代码卸载 (示例代码指向底部)很有趣,因为它通常适用于安装程序的所有版本和版本(升级代码往往在各个发行版中都保持稳定)。

CMD.EXE : Personally I might just use an install and an uninstall batch file. CMD.EXE :就我个人而言,我可能只使用安装和卸载批处理文件。 More of these samples in section 3 here . 第3节中的更多示例 Just create two different files: 只需创建两个不同的文件:

  • Install : msiexec.exe /i "c:\\Setup.msi" /QN /L*V "C:\\msi.log" REBOOT=ReallySuppress 安装msiexec.exe /i "c:\\Setup.msi" /QN /L*V "C:\\msi.log" REBOOT=ReallySuppress

  • Uninstall : msiexec.exe /x "c:\\Setup.msi" /QN /L*V "C:\\msi.log" REBOOT=ReallySuppress 卸载msiexec.exe /x "c:\\Setup.msi" /QN /L*V "C:\\msi.log" REBOOT=ReallySuppress

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试将WCF应用程序上载到服务器时出现错误 - Getting error when I am trying to upload WCF application to the server WMI无效的类错误(尝试在远程PC上卸载软件) - WMI invalid Class error (trying to uninstall a software on remote pc) 以编程方式卸载应用程序 - Uninstall an application programmatically 如何卸载 ClickOnce 应用程序? - How to uninstall ClickOnce application? 如何以编程方式卸载应用程序 - How to uninstall application programmatically 告诉应用程序自动卸载? - Tell application to automatically uninstall? 尝试使用asp.net Web应用程序将数据插入SQL Server数据库,出现错误 - Trying to insert data into SQL Server database using asp.net web application, getting an error 如果尝试下载我的独立应用程序时出现错误:无法找到运行该应用程序的运行时版本 - Getting error if trying to download my standalone app: Unable to find a version of the runtime to run this application 尝试访问IIS中托管的应用程序时出现“无法找到资源”错误 - getting “The resource cannot be found” error when trying to access application hosted in IIS 为什么在我的 Asp.NetCore 应用程序中尝试包含对 UserServiceBaseLifetime() 的调用时出现编译器错误? - Why am I getting a compiler error trying to include a call to UserServiceBaseLifetime() in my Asp.NetCore application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM