標籤: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#卸載某個應用軟體