private void InstallSendResults(Operations.SavedOpData updateData, RvSofOperation operation, List <RVsofResult.AppsToAdd2> appsToAdd = null, List <RVsofResult.AppsToDelete2> appsToDelete = null) { try { var results = new RVsofResult(); results.AppsToAdd = results.AppsToAdd != null ? appsToAdd : new List <RVsofResult.AppsToAdd2>(); results.AppsToDelete = results.AppsToDelete != null ? appsToDelete : new List <RVsofResult.AppsToDelete2>(); results.AppId = updateData.filedata_app_id; results.Operation = updateData.operation; results.OperationId = updateData.operation_id; results.Error = updateData.error; results.RebootRequired = updateData.reboot_required; results.Success = updateData.success; switch (updateData.operation) { case OperationValue.InstallWindowsUpdate: results = WindowsUpdates.AddAppDetailsToResults(results); operation.RawResult = RvFormatter.Install(results); break; case OperationValue.InstallCustomApp: results = CustomAppsManager.AddAppDetailsToResults(results); operation.RawResult = RvFormatter.Install(results); break; case OperationValue.InstallSupportedApp: results = SupportedAppsManager.AddAppDetailsToResults(results); operation.RawResult = RvFormatter.Install(results); break; case OperationValue.InstallAgentUpdate: results = AgentUpdateManager.AddAppDetailsToResults(results); operation.RawResult = RvFormatter.AgentUpdate(results); break; case OperationValue.Uninstall: operation.RawResult = RvFormatter.Install(results); break; } operation.Id = updateData.operation_id; operation.Plugin = "rv"; Operations.UpdateStatus(updateData, Operations.OperationStatus.ResultsPending); Logger.Log("Sending back results for {0}.", LogLevel.Info, updateData.filedata_app_name); if (SendResults(operation)) { Operations.CleanAllOperationData(updateData); } } catch (Exception e) { Logger.Log("Failed when attempting to send back results, Exception inside InstallSendResults()."); Logger.LogException(e); } }
/// <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); }
private static List <Application> NewUpdatesAndApplications() { var applications = new List <Application>(); applications.AddRange(WindowsUpdates.GetAvailableUpdates()); applications.AddRange(WindowsUpdates.GetInstalledUpdates()); applications.AddRange(SupportedAppsManager.GetInstalledApplications()); return(applications); }
private static Dictionary <string, string> ParseWinNT51_52Keys() { // With NT 5.1 and 5.2 (XP and Server 2003/XP 64bit) Windows uninstalled updates by the // SOFTWARE\Microsoft\Updates registry key. Then using the "UninstallCommand" key within. // Registry Keys used to uninstall updates. First is default; Second is for 32bit apps on 64bit Windows. var uninstallKeys = new List <string>(); uninstallKeys.Add(@"SOFTWARE\Microsoft\Updates\Windows XP"); var uninstallDict = new Dictionary <string, string>(); // Ugly iteration of the registry keys. foreach (string key in uninstallKeys) { using (RegistryKey rootXpKey = Registry.LocalMachine.OpenSubKey(key)) { if (rootXpKey != null) { foreach (var subName in rootXpKey.GetSubKeyNames()) { using (var subKey = rootXpKey.OpenSubKey(subName)) { if (subKey != null) { foreach (var kbName in subKey.GetSubKeyNames()) { using (var kbKey = subKey.OpenSubKey(kbName)) { if (kbKey != null && ((kbKey.GetValue("Description") != null) && (kbKey.GetValue("UninstallCommand") != null))) { var kbString = WindowsUpdates.GetKbString(kbKey.GetValue("Description").ToString()); var uninstallString = kbKey.GetValue("UninstallCommand").ToString(); if (!uninstallDict.ContainsKey(kbString)) { uninstallDict.Add(kbString, uninstallString); } } } } } } } } } } return(uninstallDict); }
private Dictionary <string, string> ParseUninstallKeys() { // This logic is only reliable for packages/applications that install system wide "UninstallString" keys in the // Windows registry (aka "the pit of horse shit"). // Registry Keys used to uninstall apps. First is default; Second is for 32bit apps on 64bit Windows. var uninstallKeys = new List <string>(); uninstallKeys.Add(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); if (_win64) { uninstallKeys.Add(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"); } var programDict = new Dictionary <string, string>(); foreach (var key in uninstallKeys) { using (var rKey = Registry.LocalMachine.OpenSubKey(key)) { if (rKey != null) { foreach (var skName in rKey.GetSubKeyNames()) { using (var sk = rKey.OpenSubKey(skName)) { if (sk != null && ((sk.GetValue("DisplayName") != null) && (sk.GetValue("UninstallString") != null))) { var kbString = WindowsUpdates.GetKbString(sk.GetValue("DisplayName").ToString()); var uninstallString = sk.GetValue("UninstallString").ToString(); if (!programDict.ContainsKey(kbString)) { programDict.Add(kbString, uninstallString); } } } } } } } return(programDict); }
private void UninstallOperation(RvSofOperation operation) { var registry = new RegistryReader(); var tempAppsToAdd = new List <RVsofResult.AppsToAdd2>(); var tempAppsToDelete = new List <RVsofResult.AppsToDelete2>(); var savedOperations = Operations.LoadOpDirectory().Where(p => p.operation == OperationValue.Uninstall).ToList(); if (!savedOperations.Any()) { Logger.Log("There are no operations remaining, Unable to uninstall app: {0}", LogLevel.Warning, operation.Type); return; } foreach (var localOp in savedOperations) { if (operation.ListOfInstalledApps.Any()) { operation.ListOfInstalledApps.Clear(); } if (operation.ListOfAppsAfterInstall.Any()) { operation.ListOfAppsAfterInstall.Clear(); } //Retrieve a list of all updates installed in the system before uninstalling anything. operation.ListOfInstalledApps = registry.GetRegistryInstalledApplicationNames(); Operations.UpdateStatus(localOp, Operations.OperationStatus.Processing); var msiUninstall = new MSIUninstaller.MSIprop(); try { if (localOp.filedata_app_name != String.Empty) { msiUninstall = MSIUninstaller.UnistallApp(localOp.filedata_app_name); } } catch { Logger.Log("MSIuninstaller crashed while attempting to uninstall {0}", LogLevel.Error, localOp.filedata_app_name); msiUninstall.UninstallPass = false; } Application update = null; if (!msiUninstall.UninstallPass) { var installedUpdates = WindowsUpdates.GetInstalledUpdates(); update = (from n in installedUpdates where n.Name == localOp.filedata_app_name select n).FirstOrDefault(); } var uninstallerResults = new UninstallerResults(); if (!msiUninstall.UninstallPass) { try { uninstallerResults = WindowsUninstaller.Uninstall(update); } catch { Logger.Log("Windows Uninstall Update failed.", LogLevel.Error); uninstallerResults.Success = false; } } //Get all installed application after installing.. operation.ListOfAppsAfterInstall = registry.GetRegistryInstalledApplicationNames(); //GET DATA FOR APPSTOADD/APPSTODELETE var appListToDelete = RegistryReader.GetAppsToDelete(operation.ListOfInstalledApps, operation.ListOfAppsAfterInstall); var appListToAdd = RegistryReader.GetAppsToAdd(operation.ListOfInstalledApps, operation.ListOfAppsAfterInstall); //APPS TO DELETE #region Apps to Delete if (appListToDelete != null) { var temp = registry.GetAllInstalledApplicationDetails(); foreach (var app in appListToDelete) { var appsToDelete = new RVsofResult.AppsToDelete2(); var version = (from d in temp where d.Name == localOp.filedata_app_name select d.Version).FirstOrDefault(); appsToDelete.Name = (String.IsNullOrEmpty(app)) ? String.Empty : app; appsToDelete.Version = (String.IsNullOrEmpty(version)) ? String.Empty : version; tempAppsToDelete.Add(appsToDelete); } } #endregion //APPS TO ADD #region Apps to Add if (appListToAdd != null) { var installedAppsDetails = registry.GetAllInstalledApplicationDetails(); foreach (var app in appListToAdd) { var temp = new RVsofResult.AppsToAdd2(); var localApp = app; var version = (from d in installedAppsDetails where d.Name == localOp.filedata_app_name select d.Version).FirstOrDefault(); //Default NULL var vendor = (from d in installedAppsDetails where d.Name == localApp select d.VendorName).FirstOrDefault(); //Default NULL var installDate = Tools.ConvertDateToEpoch((from d in installedAppsDetails where d.Name == localApp select d.Date).FirstOrDefault()); //Default 0.0D temp.AppsToAdd.Name = (String.IsNullOrEmpty(localApp)) ? String.Empty : localApp; temp.AppsToAdd.Version = (String.IsNullOrEmpty(version)) ? String.Empty : version; temp.AppsToAdd.InstallDate = (installDate.Equals(0.0D)) ? 0.0D : installDate; temp.AppsToAdd.VendorName = (String.IsNullOrEmpty(vendor)) ? String.Empty : vendor; temp.AppsToAdd.RebootRequired = "no"; temp.AppsToAdd.ReleaseDate = 0.0; temp.AppsToAdd.Status = "installed"; temp.AppsToAdd.Description = String.Empty; temp.AppsToAdd.SupportUrl = String.Empty; temp.AppsToAdd.VendorId = String.Empty; temp.AppsToAdd.VendorSeverity = String.Empty; temp.AppsToAdd.KB = String.Empty; tempAppsToAdd.Add(temp); } } #endregion if (uninstallerResults.Success || msiUninstall.UninstallPass) { // Success! Uinstalled OK localOp.success = true.ToString().ToLower(); localOp.reboot_required = String.IsNullOrEmpty(uninstallerResults.Restart.ToString()) ? "no" : uninstallerResults.Restart.ToString(); localOp.error = string.Empty; operation.Api = ApiCalls.RvUninstallOperation(); operation.Type = OperationValue.Uninstall; operation.Id = localOp.operation_id; InstallSendResults(localOp, operation, tempAppsToAdd, tempAppsToDelete); } else { // Fail! Uinstalled Failed. localOp.success = false.ToString().ToLower(); localOp.reboot_required = String.IsNullOrEmpty(uninstallerResults.Restart.ToString()) ? "no" : uninstallerResults.Restart.ToString(); localOp.error = "Unable to successfully uninstall application. If this is not a Windows Update Uninstall, ensure that the application is of type MSI We currently do not support other installers. Error: " + msiUninstall.Error; operation.Api = ApiCalls.RvUninstallOperation(); operation.Type = OperationValue.Uninstall; operation.Id = localOp.operation_id; InstallSendResults(localOp, operation, tempAppsToAdd, tempAppsToDelete); } } }
private void InstallWindowsUpdate(RvSofOperation operation) { var savedOperations = Operations.LoadOpDirectory().Where(p => p.operation == OperationValue.InstallWindowsUpdate).ToList(); if (!savedOperations.Any()) { Logger.Log("There are no operations remaining, Unable to install windows update: {0}", LogLevel.Warning, operation.Type); return; } WindowsUpdates.PopulateAvailableUpdatesList(); WindowsUpdates.PopulateInstalledUpdatesList(); foreach (var update in savedOperations) { //Check if update is already installed. /////////////////////////////////////////////////////////////////////////////////////////// if (WindowsUpdates.IsUpdateInstalled(update.filedata_app_name)) { Logger.Log("Update is already installed ({0}), sending back results.", LogLevel.Info, update.filedata_app_name); Operations.UpdateStatus(update, Operations.OperationStatus.ResultsPending); InstallSendResults(update, operation); continue; //Move on to next update. } Logger.Log("Preparing to download"); Operations.SavedOpData updateDownloadResults = Downloader.DownloadFile(update, Downloader.UpdateDirectories.OSUpdateDir); //If download fails, send back results to server and move to next package (if any). //////////////////////////////////////////////////////////////////////////////////////////// if (!String.IsNullOrEmpty(updateDownloadResults.error)) { Operations.UpdateStatus(updateDownloadResults, Operations.OperationStatus.ResultsPending); InstallSendResults(updateDownloadResults, operation); continue; } Logger.Log("Download completed for {0}", LogLevel.Info, update.filedata_app_name); Logger.Log("Installing {0} ", LogLevel.Info, update.filedata_app_name); Operations.SavedOpData updateInstallResults = WindowsUpdates.InstallWindowsUpdate(update); //If installation fails, send back results to server and move to next package (if any). ///////////////////////////////////////////////////////////////////////////////////////////// if (!String.IsNullOrEmpty(updateInstallResults.error)) { Operations.UpdateStatus(updateDownloadResults, Operations.OperationStatus.ResultsPending); InstallSendResults(updateInstallResults, operation); continue; } Logger.Log("Installation of {0} was a success.", LogLevel.Info, update.filedata_app_name); Operations.UpdateStatus(updateDownloadResults, Operations.OperationStatus.ResultsPending); ///////////////////////////////////////////////////////////////////////////////////////////////////////// //Check scenerio for this update, react accordingly. ///////////////////////////////////////////////////////////////////////////////////////////////////////// if (Convert.ToBoolean(updateInstallResults.reboot_required) && Convert.ToBoolean(updateInstallResults.success) && (updateInstallResults.restart == "optional" || updateInstallResults.restart == "forced")) { Operations.UpdateOperation(updateInstallResults, true, true, Operations.OperationStatus.Rebooting); Operations.DeleteLocalUpdateBundleFolder(updateInstallResults); Logger.Log("Rebooting system as per update requirement."); RvUtils.RestartSystem(); Stop(); //System will restart to continue Windows update configuration, then ResumeOperations will start where we left off. } else if (Convert.ToBoolean(updateInstallResults.reboot_required) && !Convert.ToBoolean(updateInstallResults.success) && (updateInstallResults.restart == "optional" || updateInstallResults.restart == "forced")) { Operations.UpdateOperation(updateInstallResults, false, true, Operations.OperationStatus.Rebooting); Operations.DeleteLocalUpdateBundleFolder(updateInstallResults); Logger.Log("Rebooting system as per update requirement."); RvUtils.RestartSystem(); Stop(); //System will restart to continue Windows update configuration, then ResumeOperations will start where we left off. } else if (Convert.ToBoolean(updateInstallResults.reboot_required) && Convert.ToBoolean(updateInstallResults.success) && updateInstallResults.restart == "none") { InstallSendResults(updateInstallResults, operation); } else if (Convert.ToBoolean(updateInstallResults.reboot_required) && !Convert.ToBoolean(updateInstallResults.success) && updateInstallResults.restart != "none") { Operations.UpdateOperation(updateInstallResults, false, true, Operations.OperationStatus.Rebooting); Operations.DeleteLocalUpdateBundleFolder(updateInstallResults); RvUtils.RestartSystem(); Stop(); //System will restart to continue Windows update configuration, then ResumeOperations will start where we left off. } else if (Convert.ToBoolean(updateInstallResults.reboot_required) && updateInstallResults.restart != "none") { var isInstalled = WindowsUpdates.IsUpdateInstalled(updateInstallResults.filedata_app_name); Logger.Log("Rebooting system as per update requirement."); Operations.UpdateOperation(updateInstallResults, isInstalled, true, Operations.OperationStatus.Rebooting); RvUtils.RestartSystem(); Stop(); //System will restart to continue Windows update configuration, then ResumeOperations will start where we left off. } else { InstallSendResults(updateInstallResults, operation); } } }