C#卸載某個應用軟體

來源:互聯網
上載者:User

標籤:style   blog   color   io   os   使用   ar   for   div   

 1 using Microsoft.Win32; 2 using System; 3 using System.Collections.Generic; 4 using System.Diagnostics; 5 using System.Linq; 6 using System.Text; 7 using System.Threading.Tasks; 8  9 namespace UpdateModule10 {11     class SoftUnInstall12     {13         //static void Main(string[] args)14         //{15 16         //    UnInstall();17  18         //}19 20         //擷取軟體的ProductCode,卸載時候使用21         public static string GetProductCode(string displayName)22         {23             string productCode = string.Empty;24 25             // 如果是32位作業系統,(或者系統是64位,程式也是64位)26             string bit32 = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";27             // 如果作業系統是64位並且程式是32位的28             string bit64 = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";29 30             RegistryKey localMachine = Registry.LocalMachine;31             RegistryKey Uninstall = localMachine.OpenSubKey(bit32, true);32 33             foreach (string subkey in Uninstall.GetSubKeyNames())34             {35                 RegistryKey productcode = Uninstall.OpenSubKey(subkey);36                 try37                 {38                     string displayname = productcode.GetValue("DisplayName").ToString();39                     if (displayname == displayName)40                     {41                         string uninstallString = productcode.GetValue("UninstallString").ToString();42 43                         string[] strs = uninstallString.Split(new char[2] { ‘{‘, ‘}‘ });44                         productCode = strs[1];45                         return productCode;46                     }47                 }48                 catch { }49             }50 51 52             return productCode;53         }54 55         //卸載軟體函數,只需要卸載終端,無須卸載36056         public static void UnInstall() 57         {58             Process p = new Process();59             p.StartInfo.FileName = "msiexec.exe";60             string str1 = GetProductCode("SecurityManager");   61             p.StartInfo.Arguments = "/x {" + str1 + "} /quiet /norestart";62             p.Start();63         }64 65     }66 }

 

C#卸載某個應用軟體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.