/// <summary> /// Searches the registry to get a list of installed apps on the computer. /// </summary> /// <returns>Returns a list of "Application".</returns> public static List<Application> GetInstalledApplications() { //Retrieve installed application details: //Name, VendorName, Version, InstallDate var regReader = new RegistryReader(); var installedApps = new List<Application>(); Logger.Log("Retrieving installed applications."); try { var myreg = regReader.GetAllInstalledApplicationDetails(); foreach (var x in myreg.Where(p => p.Name != "")) { var app = new Application(); app.VendorName = (String.IsNullOrEmpty(x.VendorName) ? String.Empty : x.VendorName); app.Name = (String.IsNullOrEmpty(x.Name) ? String.Empty : x.Name); app.Version = (String.IsNullOrEmpty(x.Version) ? String.Empty : x.Version); try { app.InstallDate = Convert.ToDouble(x.Date); } catch (Exception) { app.InstallDate = 0.0; } app.Status = "Installed"; Logger.Log(app.Name, LogLevel.Info); installedApps.Add(app); } } catch (Exception e) { Logger.Log("Failed to get installed application details. Skipping.", LogLevel.Error); Logger.LogException(e); } return installedApps; }
public UninstallerResults Uninstall(Application update) { var results = new UninstallerResults(); switch (_winVersion) { case NTVersion.Server2003: case NTVersion.Xp: results = WinNT51_52Procedure(update); break; case NTVersion.VistaServer2008: results = WinNT60Procedure(update); break; case NTVersion.SevenServer2008R2: results = WinNT61Procedure(update); break; case NTVersion.EightServer2012: results = WinNT61Procedure(update); break; } return results; }
private static Application ConvertToApplication(IUpdate iUpdate, IEnumerable history = null, bool isWsusEnabled = false) { var tpUpdate = new Application(); string vendorId; // If a vendor Id is not provided, we create one for it. if ((iUpdate.Identity.UpdateID == null) || (iUpdate.Identity.UpdateID.Equals(String.Empty))) vendorId = Guid.NewGuid().ToString(); else vendorId = iUpdate.Identity.UpdateID; tpUpdate.Name = iUpdate.Title; tpUpdate.VendorName = "Microsoft"; tpUpdate.VendorId = vendorId; tpUpdate.Description = iUpdate.Description; tpUpdate.SupportUrl = (iUpdate.MoreInfoUrls.Count <= 0) ? Settings.EmptyValue : iUpdate.MoreInfoUrls[0]; tpUpdate.VendorSeverity = iUpdate.MsrcSeverity ?? Settings.EmptyValue; tpUpdate.KB = GetKbString(iUpdate.Title); tpUpdate.InstallDate = GetDateInstalled(history, iUpdate.Identity.UpdateID); tpUpdate.ReleaseDate = Tools.ConvertDateToEpoch(iUpdate.LastDeploymentChangeTime.ToString("yyyyMMdd")); tpUpdate.Status = iUpdate.IsInstalled ? "Installed" : "Available"; switch (iUpdate.InstallationBehavior.RebootBehavior) { case InstallationRebootBehavior.irbAlwaysRequiresReboot: tpUpdate.RebootRequired = "yes"; break; case InstallationRebootBehavior.irbCanRequestReboot: tpUpdate.RebootRequired = "possible"; break; case InstallationRebootBehavior.irbNeverReboots: tpUpdate.RebootRequired = "no"; break; } var bundlesForUpdate = GetAllUpdates(iUpdate, isWsusEnabled); if (!iUpdate.IsInstalled) Operations.SaveAvailableUpdateToDisk(iUpdate.Identity.UpdateID, bundlesForUpdate); foreach (var item in bundlesForUpdate) { tpUpdate.FileData.AddRange(item.Value); } return tpUpdate; }
/// <summary> /// Uninstall updates on Windows XP & Windows Server 2003 & R2. /// </summary> /// <param name="update">Update to uninstall.</param> private UninstallerResults WinNT51_52Procedure(Application update) { UninstallerResults results; // Arguments used by "spuninst.exe" const string noGui = "/quiet"; const string noRestart = "/norestart"; var arguments = String.Format("{0} {1}", noGui, noRestart); // Process that's going to run the uninstalltion application var keys = ParseWinNT51_52Keys(); if (!keys.ContainsKey(update.KB)) { results = ProcessUninstallerResults(WindowsExitCode.UpdateNotFound); return results; } var spuninstProcess = keys[update.KB].ToString(CultureInfo.InvariantCulture); var exitCode = WindowsProcess(spuninstProcess, arguments); results = ProcessUninstallerResults(exitCode); return results; }
/// <summary> /// Uninstall updates on Windows 7 & Windows Server 2008 R2. (6.1) /// </summary> /// <param name="update">Update to uninstall.</param> private static UninstallerResults WinNT61Procedure(Application update) { // TODO: NOT FULLY BAKED!!!! Doesn't check registry for updates that could be there. IEnumerable<WindowsUpdates.QfeData> qfeList = WindowsUpdates.QueryWmiHotfixes(); var temp = new UninstallerResults(); foreach (WindowsUpdates.QfeData qfe in qfeList) { try { if (qfe.HotFixId.Equals(update.KB)) { return WusaProcess(update.KB); } } catch (Exception) { temp.Message = "This update does not appear to be Uninstallable. Unable to remove."; temp.Success = false; temp.Restart = false; temp.ExitCode = WindowsExitCode.NotAllowed; //TODO: HARDCODED :) MUAHAHAHA. MUST FIX! } } return temp; }
/// <summary> /// Uninstall updates on Windows Vista & Windows Server 2008. /// </summary> /// <param name="update">Update to uninstall.</param> private static UninstallerResults WinNT60Procedure(Application update) { UninstallerResults results; Logger.Log("In WinNT60Procedure."); var cabFilePath = FindCabFile(update.KB); if (cabFilePath == null) { results = ProcessUninstallerResults(WindowsExitCode.UpdateNotFound); return results; } // Arguments used by "pkgmgr.exe" const string noGui = "/quiet"; const string noRestart = "/norestart"; // /up is the uninstall command. /s is a temp sandbox directory where to unpack the CAB file. var arguments = String.Format(@"/m:{0} /up /s:{1} {2} {3}", cabFilePath, Path.Combine(Path.GetTempPath(), update.KB), noGui, noRestart); var exitCode = WindowsProcess("pkgmgr.exe", arguments); results = ProcessUninstallerResults(exitCode); return results; }