private void FrmPrerequisiteSubscribers_Shown(object sender, EventArgs e) { Logger.EnteringMethod(); this.Cursor = Cursors.WaitCursor; if (updateToDelete != null) { dgvUpdates.Rows.Clear(); WsusWrapper wsus = WsusWrapper.GetInstance(); UpdateScope scope = new UpdateScope(); scope.UpdateSources = UpdateSources.All; UpdateCollection allUpdates = wsus.GetAllUpdates(scope); foreach (IUpdate update in allUpdates) { if (update.IsEditable) { SoftwareDistributionPackage sdp = wsus.GetMetaData(update); if (sdp != null) { IList <PrerequisiteGroup> prerequisites = sdp.Prerequisites; if (wsus.PrerequisitePresent(prerequisites, updateToDelete.Id.UpdateId)) { Logger.Write("adding update : " + update.Title); AddRow(update); } } } } } this.Cursor = Cursors.Default; }
private IUpdate PublishUpdate(IUpdateCategory productToDelete, IUpdateCategory vendorToDelete) { Logger.EnteringMethod("Product to Delete : " + productToDelete.Title + " and Vendor to delete : " + vendorToDelete.Title); try { SoftwareDistributionPackage sdp = new SoftwareDistributionPackage(); string tmpFolderPath; sdp.PopulatePackageFromExe("ProductKiller.exe"); sdp.Title = "Delete Me !"; sdp.Description = "Delete Me !"; sdp.VendorName = vendorToDelete.Title; sdp.ProductNames.Clear(); sdp.ProductNames.Add(productToDelete.Title); sdp.PackageType = PackageType.Update; tmpFolderPath = GetTempFolder(); if (!System.IO.Directory.Exists(tmpFolderPath + sdp.PackageId)) { System.IO.Directory.CreateDirectory(tmpFolderPath + sdp.PackageId); } if (!System.IO.Directory.Exists(tmpFolderPath + sdp.PackageId + "\\Xml\\")) { System.IO.Directory.CreateDirectory(tmpFolderPath + sdp.PackageId + "\\Xml\\"); } if (!System.IO.Directory.Exists(tmpFolderPath + sdp.PackageId + "\\Bin\\")) { System.IO.Directory.CreateDirectory(tmpFolderPath + sdp.PackageId + "\\Bin\\"); } System.IO.FileInfo updateFile = new System.IO.FileInfo("ProductKiller.exe"); updateFile.CopyTo(tmpFolderPath + sdp.PackageId + "\\Bin\\" + updateFile.Name); sdp.Save(tmpFolderPath + sdp.PackageId + "\\Xml\\" + sdp.PackageId.ToString() + ".xml"); IPublisher publisher = wsus.GetPublisher(tmpFolderPath + sdp.PackageId + "\\Xml\\" + sdp.PackageId.ToString() + ".xml"); publisher.PublishPackage(tmpFolderPath + sdp.PackageId + "\\Bin\\", null); System.Threading.Thread.Sleep(5000); UpdateCollection publishedUpdates = productToDelete.GetUpdates(); if (publishedUpdates.Count == 1) { Logger.Write("Successfuly publish ProductKiller"); return(publishedUpdates[0]); } else { Logger.Write("Failed to publish ProductKiller"); return(null); } } catch (Exception ex) { Logger.Write("**** " + ex.Message); return(null); } }
/// <summary> /// Parse a XML file and create needed SoftwareDistrubutionPackages. /// </summary> /// <param name="xmlFilePath">Full path to the XML file.</param> private List <SoftwareDistributionPackage> ParseXMLFile(string xmlFilePath) { Logger.EnteringMethod(xmlFilePath); List <SoftwareDistributionPackage> extractedSDP = new List <SoftwareDistributionPackage>(); XmlNamespaceManager namespaceMgr = new XmlNamespaceManager(new NameTable()); int percentProgress = 0; namespaceMgr.AddNamespace("", "http://www.w3.org/2001/XMLSchema"); namespaceMgr.AddNamespace("smc", "http://schemas.microsoft.com/sms/2005/04/CorporatePublishing/SystemsManagementCatalog.xsd"); XmlDocument xmlDoc = new XmlDocument(); try { xmlDoc.Load(xmlFilePath); XmlNodeList selectedNodes = xmlDoc.SelectNodes("smc:SystemsManagementCatalog/smc:SoftwareDistributionPackage", namespaceMgr); int nodeCount = selectedNodes.Count; int currentNode = 1; List <XmlNode> nodes = new List <XmlNode>(); foreach (XmlNode node in selectedNodes) { nodes.Add(node); } System.Threading.Tasks.Parallel.ForEach <XmlNode>(nodes, node => { try { SoftwareDistributionPackage sdp = new SoftwareDistributionPackage(node.CreateNavigator()); extractedSDP.Add(sdp); } catch (Exception) { } percentProgress = (int)(currentNode * 100 / nodeCount); if (OpenCatalogProgression != null) { OpenCatalogProgression(percentProgress); } currentNode++; }); } catch (Exception ex) { Logger.Write("**** " + ex.Message); System.Windows.Forms.MessageBox.Show(ex.Message); } Logger.Write("Will return " + extractedSDP.Count + " SDP."); return(extractedSDP); }
internal void Revise(SoftwareDistributionPackage sdp) { Logger.EnteringMethod(); System.Resources.ResourceManager resManager = new System.Resources.ResourceManager("Wsus_Package_Publisher.Resources.Resources", typeof(FrmUpdatePublisher).Assembly); btnOk.Enabled = false; prgBrPublishing.Value = 0; PresetVisibleInWsusConsoleChkBx(); this.Refresh(); _wsus.UpdatePublishingProgress += new WsusWrapper.UpdatePublishingProgressEventHandler(publisher_Progress); _wsus.ReviseUpate(_informationsWizard, _isInstalledRulesWizard, _isInstallableRulesWizard, sdp); lblUpdatePublished.Text = resManager.GetString("UpdateRevised"); btnOk.Enabled = true; }
internal void CopyInformations(SoftwareDistributionPackage softwareDistributionPackage) { Logger.EnteringMethod(softwareDistributionPackage.Title); Company selectedCompany = null; Product selectedProduct = null; foreach (Company company in _companies.Values) { if (company.CompanyName.ToLower() == softwareDistributionPackage.VendorName.ToLower()) { selectedCompany = company; break; } } if (selectedCompany != null) { foreach (Product product in selectedCompany.Products.Values) { if (product.ProductName.ToLower() == softwareDistributionPackage.ProductNames[0].ToLower()) { selectedProduct = product; break; } } } InitializeComponent(selectedCompany, selectedProduct, softwareDistributionPackage); txtBxSecurityBulletinId.Text = string.Empty; chkCmbBxCveID.ClearItems(); txtBxKBArticleId.Text = string.Empty; foreach (object item in chkCmbBxSupersedes.Items) { if (item.ToString() != softwareDistributionPackage.Title) { chkCmbBxSupersedes.SelectItem(item, false); } else { chkCmbBxSupersedes.SelectItem(item, true); } } }
internal FrmUpdateInformationsWizard(Dictionary <Guid, Company> Companies, Company SelectedCompany, Product SelectedProduct, SoftwareDistributionPackage sdp) { Logger.EnteringMethod("FrmUpdateInformationsWizard"); IsRevising = (sdp != null); InitializeComponent(); this.VisibleChanged += new EventHandler(FrmUpdateInformationsWizard_VisibleChanged); DataGridViewComboBoxColumn column = (DataGridViewComboBoxColumn)dtgrvReturnCodes.Columns["Result"]; column.Items.Add(resMan.GetString("Failed")); column.Items.Add(resMan.GetString("Succeeded")); column.Items.Add(resMan.GetString("Cancelled")); _companies = Companies; FillPrerequisites(); InitializeComponent(SelectedCompany, SelectedProduct, sdp); toolTipAutoApprovalRules.IsBalloon = false; toolTipAutoApprovalRules.ToolTipIcon = ToolTipIcon.Info; toolTipAutoApprovalRules.ToolTipTitle = resMan.GetString("AutoApprovalRules"); toolTipAutoApprovalRules.UseAnimation = true; toolTipAutoApprovalRules.UseFading = true; }
private void InitializeComponent(Company SelectedCompany, Product SelectedProduct, SoftwareDistributionPackage sdp) { Logger.EnteringMethod(); cmbBxUpdateClassification.Items.Clear(); cmbBxUpdateClassification.Items.AddRange(Enum.GetNames(typeof(PackageUpdateClassification))); cmbBxUpdateClassification.SelectedItem = PackageUpdateClassification.Updates.ToString(); cmbBxPackageType.Items.Clear(); cmbBxPackageType.Items.AddRange(Enum.GetNames(typeof(PackageType))); cmbBxPackageType.SelectedItem = PackageType.Application.ToString(); cmbBxImpact.Items.Clear(); cmbBxImpact.Items.AddRange(Enum.GetNames(typeof(InstallationImpact))); cmbBxImpact.SelectedItem = InstallationImpact.Normal.ToString(); cmbBxRebootBehavior.Items.Clear(); cmbBxRebootBehavior.Items.AddRange(Enum.GetNames(typeof(RebootBehavior))); cmbBxRebootBehavior.SelectedItem = RebootBehavior.CanRequestReboot.ToString(); cmbBxMsrcSeverity.Items.Clear(); cmbBxMsrcSeverity.Items.AddRange(Enum.GetNames(typeof(SecurityRating))); cmbBxMsrcSeverity.SelectedItem = SecurityRating.None.ToString(); cmbBxVendorName.Select(); _description = resMan.GetString("NoDescription"); cmbBxVendorName.Items.Clear(); foreach (Company company in _companies.Values) { cmbBxVendorName.Items.Add(company.CompanyName); } if (SelectedCompany != null) { Logger.Write(SelectedCompany.CompanyName); cmbBxVendorName.SelectedItem = SelectedCompany.CompanyName; } if (SelectedProduct != null) { Logger.Write(SelectedProduct.ProductName); cmbBxVendorName.SelectedItem = SelectedProduct.Vendor.CompanyName; cmbBxProductName.SelectedItem = SelectedProduct.ProductName; } if (sdp != null) { cmbBxPackageType.SelectedItem = sdp.PackageType.ToString(); txtBxTitle.Text = sdp.Title; txtBxDescription.Text = FormatDescription(sdp.Description); Logger.Write(txtBxTitle); Logger.Write(txtBxDescription); if (sdp.AdditionalInformationUrls != null && sdp.AdditionalInformationUrls.Count != 0) { txtBxMoreInfoURL.Text = sdp.AdditionalInformationUrls[0].ToString(); } if (sdp.SupportUrl != null) { txtBxSupportURL.Text = sdp.SupportUrl.ToString(); } if (sdp.InstallableItems != null && sdp.InstallableItems.Count != 0) { chkBxCanRequestUserInput.Checked = sdp.InstallableItems[0].InstallBehavior.CanRequestUserInput; chkBxRequiresNetworkConnectivity.Checked = sdp.InstallableItems[0].InstallBehavior.RequiresNetworkConnectivity; cmbBxImpact.SelectedItem = sdp.InstallableItems[0].InstallBehavior.Impact.ToString(); cmbBxRebootBehavior.SelectedItem = sdp.InstallableItems[0].InstallBehavior.RebootBehavior.ToString(); } cmbBxUpdateClassification.SelectedItem = sdp.PackageUpdateClassification.ToString(); if (!string.IsNullOrEmpty(sdp.SecurityBulletinId)) { txtBxSecurityBulletinId.Text = sdp.SecurityBulletinId; } cmbBxMsrcSeverity.SelectedItem = sdp.SecurityRating.ToString(); if (sdp.CommonVulnerabilitiesIds != null && sdp.CommonVulnerabilitiesIds.Count != 0 && !string.IsNullOrEmpty(sdp.CommonVulnerabilitiesIds[0])) { chkCmbBxCveID.ClearItems(); List <object> cveIDs = new List <object>(); foreach (string cve in sdp.CommonVulnerabilitiesIds) { cveIDs.Add(cve); } chkCmbBxCveID.AddRange(cveIDs.ToArray()); } if (!string.IsNullOrEmpty(sdp.KnowledgebaseArticleId)) { txtBxKBArticleId.Text = sdp.KnowledgebaseArticleId; } if (sdp.InstallableItems != null && sdp.InstallableItems.Count != 0) { Type updateType = sdp.InstallableItems[0].GetType(); if (updateType == typeof(CommandLineItem)) { CommandLine = (sdp.InstallableItems[0] as CommandLineItem).Arguments; ReturnCodes = (sdp.InstallableItems[0] as CommandLineItem).ReturnCodes; } else if (updateType == typeof(WindowsInstallerItem)) { CommandLine = (sdp.InstallableItems[0] as WindowsInstallerItem).InstallCommandLine; } else if (updateType == typeof(WindowsInstallerPatchItem)) { CommandLine = (sdp.InstallableItems[0] as WindowsInstallerPatchItem).InstallCommandLine; } } foreach (Guid id in sdp.SupersededPackages) { for (int i = 0; i < chkCmbBxSupersedes.Items.Count; i++) { SupersedesUpdate supersededUpdate = (SupersedesUpdate)chkCmbBxSupersedes.Items[i]; if (supersededUpdate.Update.Id.UpdateId == id) { chkCmbBxSupersedes.SelectItem(i, true); break; } } } foreach (PrerequisiteGroup prerequisiteGrp in sdp.Prerequisites) { foreach (Guid id in prerequisiteGrp.Ids) { for (int i = 0; i < chkCmbBxPrerequisites.Items.Count; i++) { Prerequisite prerequisiteUpdate = (Prerequisite)chkCmbBxPrerequisites.Items[i]; if (prerequisiteUpdate.Update.Id.UpdateId == id) { chkCmbBxPrerequisites.SelectItem(i, true); break; } } } } } }
internal CatalogUpdate(SoftwareDistributionPackage sdp) { SDP = sdp; }
internal void Import(object showInWsusConsole) { try { ShowInWsusConsole = (bool)showInWsusConsole; _overAllCurrentPosition = 0; foreach (CatalogUpdate update in _packageToImport) { while (!_downloadCompleted) { System.Threading.Thread.Sleep(1000); } _currentSDP = update.SDP; _overAllProgression = (int)(_overAllCurrentPosition * 100 / _packageToImport.Count); if (CatalogUpdateImporterProgress != null) { CatalogUpdateImporterProgress(_overAllProgression, 1, 0, resMan.GetString("Importing", _currentCulture) + " " + _currentSDP.Title); } if (_currentSDP.PackageUpdateType == PackageUpdateType.Detectoid) { PublishDetectoid(); } else if (_currentSDP.InstallableItems != null && _currentSDP.InstallableItems.Count != 0) { if (_makeLanguageIndependent) { MakeLanguageIndependent(_currentSDP); } if (_currentSDP.InstallableItems[0].OriginalSourceFile.OriginUri != null) { _downloadedFile = Tools.Utilities.GetTempFolder() + _currentSDP.InstallableItems[0].OriginalSourceFile.FileName; DownloadFile(_currentSDP.InstallableItems[0].OriginalSourceFile.OriginUri, _downloadedFile); } } else { PublishMetaDataOnly(); } } while (!_downloadCompleted) { System.Threading.Thread.Sleep(1000); } if (CatalogUpdateImporterProgress != null) { CatalogUpdateImporterProgress(100, 100, 0, resMan.GetString("AllTasksFinished", _currentCulture)); } if (CatalogUpdateImporterFinish != null) { CatalogUpdateImporterFinish(); } } catch (System.Threading.ThreadAbortException abort) { _cancel = true; Logger.Write("Abort operation : " + abort.Message); if (CatalogUpdateImporterProgress != null) { CatalogUpdateImporterProgress(0, 0, 0, resMan.GetString("Aborting", _currentCulture)); } if (webClient != null) { webClient.CancelAsync(); webClient.DownloadProgressChanged -= new DownloadProgressChangedEventHandler(DownloadProgressChanged); webClient.DownloadFileCompleted -= new System.ComponentModel.AsyncCompletedEventHandler(DownloadFileCompleted); } System.Threading.Thread.Sleep(1000); webClient = null; _downloadCompleted = true; if (CatalogUpdateImporterProgress != null) { CatalogUpdateImporterProgress(0, 0, 0, resMan.GetString("Aborted", _currentCulture)); } AbortOperation(); return; } catch (Exception ex) { Logger.Write("**** " + ex.Message); if (webClient != null) { webClient.CancelAsync(); } _downloadCompleted = true; if (CatalogUpdateImporterProgress != null) { CatalogUpdateImporterProgress(100, 100, 0, resMan.GetString("ErrorImportingUpdate", _currentCulture)); } AbortOperation(); } }
private void MakeLanguageIndependent(SoftwareDistributionPackage sdp) { sdp.InstallableItems[0].Languages.Clear(); }
private void InitializeComponent(Dictionary <Guid, Company> Companies, Company SelectedCompany, Product SelectedProduct, SoftwareDistributionPackage sdp) { Logger.EnteringMethod(); this.Companies = Companies; updateInformationsWizard = new FrmUpdateInformationsWizard(this.Companies, SelectedCompany, SelectedProduct, sdp); // UpdateFilesWizard : updateFilesWizard.TopLevel = false; updateFilesWizard.Controls["btnNext"].Click += new EventHandler(updateFilesWizard_btnNext_Click); updateFilesWizard.Controls["btnCancel"].Click += new EventHandler(updateFilesWizard_btnCancel_Click); //UpdateInformationsWizard : updateInformationsWizard.TopLevel = false; updateInformationsWizard.Controls["btnNext"].Click += new EventHandler(updateInformationsWizard_btnNext_Click); updateInformationsWizard.Controls["btnCancel"].Click += new EventHandler(updateInformationsWizard_btnCancel_Click); updateInformationsWizard.Controls["btnPrevious"].Click += new EventHandler(updateInformationsWizard_btnPrevious_Click); //updateIsInstalledRulesWizard : updateIsInstalledRulesWizard.TopLevel = false; updateIsInstalledRulesWizard.Controls["tableLayoutPanel1"].Controls["btnNext"].Click += new EventHandler(updateIsInstalledRulesWizard_btnNext_Click); updateIsInstalledRulesWizard.Controls["tableLayoutPanel1"].Controls["btnCancel"].Click += new EventHandler(updateIsInstalledRulesWizard_btnCancel_Click); updateIsInstalledRulesWizard.Controls["tableLayoutPanel1"].Controls["btnPrevious"].Click += new EventHandler(updateIsInstalledRulesWizard_btnPrevious_Click); //updateIsInstallableRulesWizard : updateIsInstallableRulesWizard.TopLevel = false; updateIsInstallableRulesWizard.Controls["tableLayoutPanel1"].Controls["btnNext"].Click += new EventHandler(updateIsInstallableRulesWizard_btnNext_Click); updateIsInstallableRulesWizard.Controls["tableLayoutPanel1"].Controls["btnCancel"].Click += new EventHandler(updateIsInstallableRulesWizard_btnCancel_Click); updateIsInstallableRulesWizard.Controls["tableLayoutPanel1"].Controls["btnPrevious"].Click += new EventHandler(updateIsInstallableRulesWizard_btnPrevious_Click); //updateApplicabilityMetadata : updateApplicabilityMetadata.TopLevel = false; updateApplicabilityMetadata.Controls["btnPublish"].Click += new EventHandler(updateApplicabilityMetadata_btnPublish_Click); updateApplicabilityMetadata.Controls["btnCancel"].Click += new EventHandler(updateApplicabilityMetadata_btnCancel_Click); updateApplicabilityMetadata.Controls["btnPrevious"].Click += new EventHandler(updateApplicabilityMetadata_btnPrevious_Click); if (Revising) { InitializeInformationsWizard(); } else { InitializeUpdateFilesWizard(); } }
private IUpdate ImportPackage(IUpdateServer wsus, string packagepath, string title, string desc, string vendor) { //Be sure that the baseapplicabilityrules.xsd exists var schemaPathx86 = Path.Combine("C:\\Program Files (x86)", "Update Services\\Schema"); var schemaPathx64 = Path.Combine("C:\\Program Files", "Update Services\\Schema"); var updateservicesPathx86 = Path.Combine("C:\\Program Files (x86)", "Update Services"); if (!File.Exists(schemaPathx86 + "baseapplicabilityrules.xsd")) { Console.WriteLine("INFO: Need to copy Update Services schemata into x86 Folder"); Console.WriteLine("DEBUG: " + schemaPathx86); Console.WriteLine("DEBUG: " + schemaPathx64); Console.WriteLine("DEBUG: " + updateservicesPathx86); if (!Directory.Exists(updateservicesPathx86)) { Directory.CreateDirectory(updateservicesPathx86); Console.WriteLine("INFO: Created Folder " + updateservicesPathx86); } if (!Directory.Exists(schemaPathx86)) { Directory.CreateDirectory(schemaPathx86); Console.WriteLine("INFO: Created Folder " + schemaPathx86); foreach (var file in Directory.GetFiles(schemaPathx64)) { File.Copy(file, Path.Combine(schemaPathx86, Path.GetFileName(file))); Console.WriteLine("INFO: Copy File " + file); } } } Console.WriteLine("Installing Package..."); SoftwareDistributionPackage sdp = new SoftwareDistributionPackage(); sdp.PopulatePackageFromWindowsInstaller(packagepath); sdp.Title = title; sdp.Description = desc; sdp.VendorName = vendor; //Look for Windows Vista sdp.IsInstallable = "<bar:WindowsVersion Comparison='GreaterThanOrEqualTo' MajorVersion='6' MinorVersion='0' />"; string sdpFilePath = Environment.GetEnvironmentVariable("TEMP") + "\\" + sdp.Title + sdp.PackageId.ToString() + ".txt"; //Superseed Update if there is one existing var searchString = title.Split(' ')[0]; foreach (IUpdate update in wsus.SearchUpdates(searchString)) { sdp.SupersededPackages.Add(update.Id.UpdateId); } sdp.Save(sdpFilePath); IPublisher publisher = wsus.GetPublisher(sdpFilePath); FileInfo dir = new FileInfo(packagepath); publisher.PublishPackage(dir.Directory.ToString(), null); Console.WriteLine("CAB generated"); IUpdate publishedUpdate = wsus.GetUpdate(new UpdateRevisionId(sdp.PackageId)); return(publishedUpdate); }