public void Start() { //Make sure WUA Is up to Date WUA.Run(); WUA.DisableAutomaticWindowsUpdates(); _updateChecker.Enable(SendNewUpdatesHandler); //Disable Java, Adobe, Acrobat Updaters DisableUpdaters.DisableAll(); //Check WSUS Status Logger.Log("WSUS enabled? {0}", LogLevel.Info, WSUS.IsWSUSEnabled()); Logger.Log("WSUS address? {0}", LogLevel.Info, WSUS.GetServerWSUS); Logger.Log("Automatic updates Enabled? {0}", LogLevel.Info, WSUS.IsAutomaticUpdatesEnabled()); try { var sysTimeZone = GetTimeZone.GetMyTimeZone(); Logger.Log("Current time zone {0}, utc off set {1}.", LogLevel.Info, sysTimeZone.time_zone, sysTimeZone.utc_offset); } catch { Logger.Log("Unable to obtain timezone.", LogLevel.Error); } switch (WSUS.GetAutomaticUpdatesOptions()) { case WSUS.AutomaticUpdateStatus.AutomaticDownloadAndNotifyOfInstall: Logger.Log("Automatic updates setting? {0}", LogLevel.Info, "Automatic download and notify of install."); break; case WSUS.AutomaticUpdateStatus.AutomaticDownloadAndScheduleInstall: Logger.Log("Automatic updates setting? {0}", LogLevel.Info, "Automatic download and schedule install."); break; case WSUS.AutomaticUpdateStatus.AutomaticUpdatesIsRequiredAndUsersCanConfigureIt: Logger.Log("Automatic updates setting? {0}", LogLevel.Info, "Automatic updates is required and users can configure it."); break; case WSUS.AutomaticUpdateStatus.NotifyBeforeDownload: Logger.Log("Automatic updates setting? {0}", LogLevel.Info, "Notify before download."); break; default: Logger.Log("Automatic updates setting? {0}", LogLevel.Info, "Not set."); break; } //Check AntiMalware and Firewall Settings Logger.Log("Anti Spyware protection? {0}", LogLevel.Info, WindowsAntiSpyware.IsProtectionEnabled()); Logger.Log("Windows firewall protection? {0}", LogLevel.Info, WindowsFirewall.IsProtectionEnabled()); //Check if system is Windows 8 and Disable automatic restarts //after critical system updates are installed. RvUtils.Windows8AutoRestart(false); }
public static List <Application> GetAvailableUpdates() { IUpdateSession session = new UpdateSession(); Logger.Log("Retrieving new os updates information..."); var availableUpdates = new List <Application>(); var wsusEnabled = WSUS.IsWSUSEnabled(); try { //Use Proxy if needed var proxyUri = Settings.GetProxyFullAddressString(); if (proxyUri != null) { session.WebProxy.Address = proxyUri; } var searcher = session.CreateUpdateSearcher(); searcher.Online = true; //Assign proper WUAPI Server (WSUS or WUS) searcher.ServerSelection = wsusEnabled ? ServerSelection.ssManagedServer : ServerSelection.ssWindowsUpdate; ISearchResult searchResults = searcher.Search("IsInstalled=0 AND Type='Software' AND DeploymentAction='Installation'"); if (searchResults == null) { searcher.Online = false; Logger.Log("Unable to retrieve available updates via the Web, attempting local search."); searchResults = searcher.Search("IsInstalled=0 AND Type='Software' AND DeploymentAction='Installation'"); } _allAvailableUpdatesList = searchResults.Updates; foreach (IUpdate update in searchResults.Updates) { availableUpdates.Add(ConvertToApplication(update, null, wsusEnabled)); Logger.Log(update.Title); } } catch (Exception e) { Logger.Log("Failed to find new updates, please check connectivity and/or Windows Update Agent version.", LogLevel.Error); Logger.LogException(e); } Logger.Log("Done."); return(availableUpdates); }
private static UpdateCollection RetrieveUpdatesAvailable() { var updateCollection = new UpdateCollection(); IUpdateSession session = new UpdateSession(); var wsusEnabled = WSUS.IsWSUSEnabled(); try { var proxyUri = Settings.GetProxyFullAddressString(); if (proxyUri != null) { session.WebProxy.Address = proxyUri; } var searcher = session.CreateUpdateSearcher(); searcher.Online = true; //Assign proper WUAPI Server (WSUS or WUS) searcher.ServerSelection = wsusEnabled ? ServerSelection.ssManagedServer : ServerSelection.ssWindowsUpdate; ISearchResult searchResults = searcher.Search("IsInstalled=0 AND Type='Software' AND DeploymentAction='Installation'"); if (searchResults == null) { searcher.Online = false; Logger.Log("Unable to retrieve available updates via the Web, attempting local search."); searchResults = searcher.Search("IsInstalled=0 AND Type='Software' AND DeploymentAction='Installation'"); } if (searchResults.ResultCode == OperationResultCode.orcSucceeded) { updateCollection = searchResults.Updates; foreach (IUpdate update in searchResults.Updates) { AllAvailableUpdatesParsed.Add(ConvertToApplication(update, null, wsusEnabled)); } } } catch (Exception e) { Logger.Log("Could not retrieve collection of updates.", LogLevel.Error); Logger.LogException(e); updateCollection = null; } return(updateCollection); }
private static UpdateCollection RetrieveUpdatesInstalled() { IUpdateSession session = new UpdateSession(); var updateCollection = new UpdateCollection(); var wsusEnabled = WSUS.IsWSUSEnabled(); try { var proxyUri = Settings.GetProxyFullAddressString(); if (proxyUri != null) { session.WebProxy.Address = proxyUri; } var searcher = session.CreateUpdateSearcher(); searcher.Online = false; //Assign proper WUAPI Server (WSUS or WUS) searcher.ServerSelection = wsusEnabled ? ServerSelection.ssManagedServer : ServerSelection.ssWindowsUpdate; ISearchResult searchResults = searcher.Search("IsInstalled = 1"); if (searchResults.ResultCode == OperationResultCode.orcSucceeded) { updateCollection = searchResults.Updates; foreach (IUpdate update in searchResults.Updates) { var parsedUpdate = ConvertToApplication(update, null, wsusEnabled); AllInstalledUpdatesParsed.Add(parsedUpdate); } } } catch (Exception e) { Logger.Log("Could not retrieve collection of installed updates.", LogLevel.Error); Logger.LogException(e); updateCollection = null; } return(updateCollection); }
public static List <Application> GetInstalledUpdates() { IUpdateSession session = new UpdateSession(); Logger.Log("Retrieving list of Installed Windows Updates."); var installedUpdates = new List <Application>(); var wsusEnabled = WSUS.IsWSUSEnabled(); try { var searcher = session.CreateUpdateSearcher(); searcher.Online = false; //Assign proper WUAPI Server (WSUS or WUS) searcher.ServerSelection = wsusEnabled ? ServerSelection.ssManagedServer : ServerSelection.ssWindowsUpdate; ISearchResult searchResults = searcher.Search("IsInstalled = 1"); _allInstalledUpdatesList = searchResults.Updates; var count = searcher.GetTotalHistoryCount(); var history = count > 0 ? searcher.QueryHistory(0, count) : null; foreach (IUpdate update in _allInstalledUpdatesList) { var parsedUpdate = ConvertToApplication(update, history, wsusEnabled); installedUpdates.Add(parsedUpdate); } } catch (Exception e) { Logger.Log("Failed to find installed updates.", LogLevel.Error); Logger.LogException(e); } Logger.Log("Done."); return(installedUpdates); }
public static Operations.SavedOpData DownloadFile(Operations.SavedOpData update, UpdateDirectories updateTypePath) { var uris = new List <DownloadUri>(); string updateDirectory; switch (updateTypePath) { case UpdateDirectories.SupportedAppDir: updateDirectory = Settings.SupportedAppDirectory; break; case UpdateDirectories.CustomAppDir: updateDirectory = Settings.CustomAppDirectory; break; case UpdateDirectories.OSUpdateDir: updateDirectory = Settings.UpdateDirectory; break; default: updateDirectory = Settings.UpdateDirectory; break; } var savedir = Path.Combine(updateDirectory, update.filedata_app_id); foreach (var uriData in update.filedata_app_uris) { var tempDownloadUri = new DownloadUri(); tempDownloadUri.FileName = uriData.file_name; tempDownloadUri.FileSize = uriData.file_size; tempDownloadUri.Hash = uriData.file_hash; //add uri link from WSUS if its enabled if (WSUS.IsWSUSEnabled()) { var tempAvilApp = Agent.RV.WindowsApps.WindowsUpdates.GetAvailableUpdates(); foreach (var application in tempAvilApp) { if (application.Name == update.filedata_app_name) { foreach (var availUri in application.FileData) { tempDownloadUri.Uris.Add(availUri.Uri); } } } } foreach (var uri in uriData.file_uris) { tempDownloadUri.Uris.Add(uri); } uris.Add(tempDownloadUri); } if (Directory.Exists(savedir)) { Directory.Delete(savedir, true); } Directory.CreateDirectory(savedir); foreach (var file in uris) { // Just in case the web server is using a self-signed cert. // Webclient won't validate the SSL/TLS cerficate if it's not trusted. var tempCallback = ServicePointManager.ServerCertificateValidationCallback; ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; var filepath = Path.Combine(savedir, file.FileName); try { using (var client = new WebClient()) { if (Settings.Proxy != null) { client.Proxy = Settings.Proxy; } var downloaded = false; foreach (var uriSingle in file.Uris) { try { var splitted = uriSingle.Split(new[] { "//" }, StringSplitOptions.RemoveEmptyEntries); var splitted2 = splitted[1].Split(new[] { '/' }); var relayserver = splitted2[0]; if (downloaded) { break; } Logger.Log("Attempting to download {1} from {0} with file size of {2}.", LogLevel.Info, relayserver, file.FileName, file.FileSize); client.DownloadFile(uriSingle, filepath); if (File.Exists(filepath)) { var localFileHashMd5 = RvUtils.Md5HashFile(filepath).ToLower(); var localFileHashSha1 = RvUtils.Sha1HashFile(filepath).ToLower(); var localFileHashSha256 = RvUtils.Sha256HashFile(filepath).ToLower(); Logger.Log("Download Complete, {0}", LogLevel.Info, file.FileName); Logger.Log("Checking Hashes..."); Logger.Log("Incoming Hash: {0}", LogLevel.Info, file.Hash); Logger.Log("Local MD5 Hash: {0}", LogLevel.Info, localFileHashMd5); Logger.Log("Local SHA1 Hash: {0}", LogLevel.Info, localFileHashSha1); Logger.Log("Local SHA256 Hash: {0}", LogLevel.Info, localFileHashSha256); downloaded = true; if (localFileHashMd5 != file.Hash.ToLower() && localFileHashSha1 != file.Hash.ToLower() && localFileHashSha256 != file.Hash.ToLower()) { Logger.Log("Local file {0} Hash did not match remote's. Retrying with a different server.", LogLevel.Info, file.FileName); update.error = "Local file Hash did not match remote. Bad file integrity. "; update.success = false.ToString().ToLower(); downloaded = false; } } else { Logger.Log("File {0} did not download. Retrying with a different server.", LogLevel.Info, file.FileName); update.error = "File did not download successfully, it was not found on disk. Please check download server."; update.success = false.ToString().ToLower(); downloaded = false; } } catch (Exception e) { Logger.Log("File {0} failed to download correctly... Possible connection issue, Retrying with a different server.", LogLevel.Info, file.FileName); update.error = "File did not download correctly, Exception message: " + e.Message + ". Please check download server connectivity."; update.success = false.ToString().ToLower(); downloaded = false; } } //Check if the file was successfully downloaded and return. if (downloaded) { update.error = String.Empty; update.success = true.ToString().ToLower(); } } } catch (Exception e) { //Critical exception occurred. update.error = "Application did not download, Exception occured, refer to log for details."; update.success = false.ToString().ToLower(); Logger.Log("One or more Application Files were not downloaded successfully; {0}.", LogLevel.Error, file.FileName); Logger.LogException(e); return(update); } ServicePointManager.ServerCertificateValidationCallback = tempCallback; } return(update); }