Annotation of cleanflash/CleanFlashCommon/Uninstaller.cs, revision 1.1.1.1

1.1       root        1: using System;
                      2: using System.Collections.Generic;
                      3: using System.Diagnostics;
                      4: using System.IO;
                      5: using System.Linq;
                      6: 
                      7: namespace CleanFlashCommon {
                      8:     public class Uninstaller {
                      9:         private static string[] PROCESSES_TO_KILL = new string[] {
                     10:             // Flash Center-related processes
                     11:             "fcbrowser", "fcbrowsermanager", "fclogin", "fctips", "flashcenter",
                     12:             "flashcenterservice", "flashcenteruninst", "flashplay", "update", "wow_helper",
                     13:             "dummy_cmd", "flashhelperservice",
                     14:             // Flash Player-related processes
                     15:             "flashplayerapp", "flashplayer_sa", "flashplayer_sa_debug",
                     16:             // Browsers that might be using Flash Player right now
                     17:             "opera", "iexplore", "chrome", "chromium", "brave", "vivaldi", "basilisk", "msedge",
                     18:             "seamonkey", "palemoon", "k-meleon", "plugin-container", "waterfox"
                     19:         };
                     20: 
                     21:         static Uninstaller() {
                     22:             WinAPI.AllowModifications();
                     23:         }
                     24: 
                     25:         public static void UninstallRegistry() {
                     26:             if (Environment.Is64BitOperatingSystem) {
                     27:                 RegistryManager.ApplyRegistry(Properties.Resources.uninstallRegistry, Properties.Resources.uninstallRegistry64);
                     28:             } else {
                     29:                 RegistryManager.ApplyRegistry(Properties.Resources.uninstallRegistry);
                     30:             }
                     31:         }
                     32: 
                     33:         public static void DeleteTask(string task) {
                     34:             ProcessRunner.RunUnmanagedProcess(
                     35:                 new ProcessStartInfo {
                     36:                     FileName = "schtasks.exe",
                     37:                     Arguments = "/delete /tn \"" + task + "\" /f",
                     38:                     UseShellExecute = false,
                     39:                     CreateNoWindow = true
                     40:                 }
                     41:             );
                     42:         }
                     43: 
                     44:         public static void StopService(string service) {
                     45:             ProcessRunner.RunUnmanagedProcess(
                     46:                 new ProcessStartInfo {
                     47:                     FileName = "net.exe",
                     48:                     Arguments = "stop \"" + service + "\"",
                     49:                     UseShellExecute = false,
                     50:                     CreateNoWindow = true
                     51:                 }
                     52:             );
                     53:         }
                     54: 
                     55:         public static void DeleteService(string service) {
                     56:             // First, stop the service.
                     57:             StopService(service);
                     58: 
                     59:             ProcessRunner.RunUnmanagedProcess(
                     60:                 new ProcessStartInfo {
                     61:                     FileName = "sc.exe",
                     62:                     Arguments = "delete \"" + service + "\"",
                     63:                     UseShellExecute = false,
                     64:                     CreateNoWindow = true
                     65:                 }
                     66:             );
                     67:         }
                     68: 
                     69:         public static void DeleteFlashCenter() {
                     70:             // Remove Flash Center from Program Files
                     71:             FileUtil.WipeFolder(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "FlashCenter"));
                     72: 
                     73:             if (Environment.Is64BitOperatingSystem) {
                     74:                 // Remove Flash Center from Program Files (x86)
                     75:                 FileUtil.WipeFolder(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "FlashCenter"));
                     76:             }
                     77: 
                     78:             // Remove start menu shortcuts
                     79:             FileUtil.WipeFolder(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Microsoft", "Windows", "Start Menu", "Programs", "Flash Center"));
                     80: 
                     81:             // Remove Flash Center cache and user data
                     82:             FileUtil.WipeFolder(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Flash_Center"));
                     83:             
                     84:             // Remove shared start menu shortcuts
                     85:             FileUtil.WipeFolder(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "Programs", "Flash Center"));
                     86:             FileUtil.WipeFolder(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Programs", "Flash Center"));
                     87:             FileUtil.DeleteFile(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Flash Player.lnk"));
                     88: 
                     89:             // Remove Desktop shortcut
                     90:             FileUtil.DeleteFile(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory), "Flash Center.lnk"));
                     91:             FileUtil.DeleteFile(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "Flash Player.lnk"));
                     92: 
                     93:             // Remove Flash Player from Program Files
                     94:             FileUtil.WipeFolder(SystemInfo.GetProgramFlash32Path());
                     95: 
                     96:             // Remove spyware dropped by Flash Center in the temporary folder   
                     97:             string tempFolder = Path.GetTempPath();
                     98: 
                     99:             foreach (string dir in Directory.GetDirectories(tempFolder)) {
                    100:                 string parentName = Path.GetFileName(dir);
                    101: 
                    102:                 if (parentName.Length == 11 && parentName.EndsWith(".tmp")) {
                    103:                     FileUtil.WipeFolder(dir);
                    104:                 }
                    105:             }
                    106: 
                    107:             // Remove Quick Launch shortcuts from Internet Explorer
                    108:             FileUtil.RecursiveDelete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Microsoft", "Internet Explorer", "Quick Launch"), "Flash Center.lnk");
                    109:         }
                    110: 
                    111:         public static void DeleteFlashPlayer() {
                    112:             // Remove Macromedia folder from System32 and SysWOW64
                    113:             foreach (string dir in SystemInfo.GetMacromedPaths()) {
                    114:                 FileUtil.RecursiveDelete(dir);
                    115:             }
                    116: 
                    117:             // Remove Flash Player control panel applications
                    118:             foreach (string systemDir in SystemInfo.GetSystemPaths()) {
                    119:                 FileUtil.DeleteFile(Path.Combine(systemDir, "FlashPlayerApp.exe"));
                    120:                 FileUtil.DeleteFile(Path.Combine(systemDir, "FlashPlayerCPLApp.cpl"));
                    121:             }
                    122:         }
                    123: 
                    124:         public static void StopProcesses() {
                    125:             // Stop all processes that might interfere with the install process
                    126:             List<Process> processes = Process.GetProcesses()
                    127:                 .Where(process => PROCESSES_TO_KILL.Contains(process.ProcessName.ToLower()))
                    128:                 .OrderBy(o => o.StartTime)
                    129:                 .ToList();
                    130: 
                    131:             foreach (Process process in processes) {
                    132:                 if (process.HasExited) {
                    133:                     // This process has already exited, no point to kill it
                    134:                     continue;
                    135:                 }
                    136: 
                    137:                 try {
                    138:                     process.Kill();
                    139:                     process.WaitForExit();
                    140:                 } catch {
                    141:                     // Could not kill process...
                    142:                 }
                    143:             }
                    144:         }
                    145: 
                    146:         public static void Uninstall(IProgressForm form) {
                    147:             // Uninstallation of Flash consists of the following steps:
                    148:             // 1. Delete all auto-updater tasks.
                    149:             // 2. Delete all Flash Player services.
                    150:             // 3. Delete all Flash Center services.
                    151:             // 4. Exit all browsers and other processes that may interfere with uninstallation.
                    152:             // 5. Remove all Flash Player references from the registry.
                    153:             // 6. Remove Flash Center files from the file system.
                    154:             // 7. Remove Flash Player files from the file system.
                    155: 
                    156:             form.UpdateProgressLabel("Stopping Flash auto-updater task...", true);
                    157:             DeleteTask("Adobe Flash Player Updater");
                    158:             form.UpdateProgressLabel("Stopping Flash auto-updater service...", true);
                    159:             DeleteService("AdobeFlashPlayerUpdateSvc");
                    160:             form.UpdateProgressLabel("Stopping Flash Center services...", true);
                    161:             DeleteService("Flash Helper Service");
                    162:             form.TickProgress();
                    163:             DeleteService("FlashCenterService");
                    164: 
                    165:             form.UpdateProgressLabel("Exiting all browsers...", true);
                    166:             StopProcesses();
                    167:             form.UpdateProgressLabel("Cleaning up registry...", true);
                    168:             UninstallRegistry();
                    169:             form.UpdateProgressLabel("Removing Flash Center...", true);
                    170:             DeleteFlashCenter();
                    171:             form.UpdateProgressLabel("Removing Flash Player...", true);
                    172:             DeleteFlashPlayer();
                    173:         }
                    174:     }
                    175: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.